Tuesday 16 May 2017

How come I get an error like "TypeError: yelp.accessToken is not a function"?

I was using the code provided by the yelp github repository.

const yelp = require('yelp-fusion');

// Place holders for Yelp Fusion's OAuth 2.0 credentials. Grab them
// from https://www.yelp.com/developers/v3/manage_app
const clientId = process.env.clientId;
const clientSecret = process.env.clientSecret;

const searchRequest = {
  term:'Four Barrel Coffee',
  location: 'san francisco, ca'
};

yelp.accessToken(clientId, clientSecret).then(response => {
  const client = yelp.client(response.jsonBody.access_token);

  client.search(searchRequest).then(response => {
    const firstResult = response.jsonBody.businesses[0];
    const prettyJson = JSON.stringify(firstResult, null, 4);
    console.log(prettyJson);
  });
}).catch(e => {
  console.log(e);
});

integrated this code correctly to my server.js and then I got the error TypeError: yelp.accessToken is not a function

when trying to execute the code from

app.get('/search', function(req, res) {   

yelp.accessToken(clientId, clientSecret).then(response => {
  var client = yelp.client(response.jsonBody.access_token);

  client.search(searchRequest).then(response => {
    var firstResult = response.jsonBody.businesses[0];
    var prettyJson = JSON.stringify(firstResult, null, 4);
    console.log(prettyJson);
  });
}).catch(e => {
  console.log(e);
}); 

and I don't know why. It should work correctly.



via Matthias Liszt

No comments:

Post a Comment