admin管理员组

文章数量:1415664

I am trying to create a function to grab my profile data from LinkedIn. For debugging though I need to see what data is being mapped over or before that. But not sure where to put my console log to see the data its receiving. Any help is much appreciated :)

// Grabs profile data from the json url
private getProfiles() {
let config = {
  headers: {'Authorization':'Bearer AQVVEqG......'}
}
axios
  .get("/" + "", config)
  .then(response => 
      response.data.map(profile => ({
        name: `${ profile.localizedLastName }`,
      }))
    )
    .then(profiles => {
      this.setState({
        profiles,
        isLoading: false
      });
    })
  // We can still use the `.catch()` method since axios is promise-based
  .catch(error => this.setState({ error, isLoading: false }));

}

I am trying to create a function to grab my profile data from LinkedIn. For debugging though I need to see what data is being mapped over or before that. But not sure where to put my console log to see the data its receiving. Any help is much appreciated :)

// Grabs profile data from the json url
private getProfiles() {
let config = {
  headers: {'Authorization':'Bearer AQVVEqG......'}
}
axios
  .get("https://cors-anywhere.herokuapp./" + "https://api.linkedin./v2/me", config)
  .then(response => 
      response.data.map(profile => ({
        name: `${ profile.localizedLastName }`,
      }))
    )
    .then(profiles => {
      this.setState({
        profiles,
        isLoading: false
      });
    })
  // We can still use the `.catch()` method since axios is promise-based
  .catch(error => this.setState({ error, isLoading: false }));

}

Share Improve this question asked Oct 4, 2019 at 13:08 BennKingyBennKingy 1,5933 gold badges27 silver badges54 bronze badges 1
  • you are not returning anything from the first Promise.then – Dan Starns Commented Oct 4, 2019 at 13:12
Add a ment  | 

2 Answers 2

Reset to default 2

Just put it in the callback function.

.then(response => {
  console.log(response);
  response.data.map(profile => ({
    name: `${ profile.localizedLastName }`,
  }))
})
.then(profiles => {
  console.log(profiles);
  this.setState({
    profiles,
    isLoading: false   
  });
})

You can do

.then(response => {
  console.log(response);
  response.data.map(profile => ({
    name: `${ profile.localizedLastName }`,
  }))
})

本文标签: javascriptWhere to put console log in axios get requestStack Overflow