为什么我会收到类似“TypeError:yelp.accessToken不是函数”的错误?

时间:2017-05-16 11:19:11

标签: node.js yelp

我使用的是yelp github存储库提供的代码。

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);
});

将此代码正确地集成到我的server.js然后我收到了错误 TypeError:yelp.accessToken不是函数

尝试执行

中的代码时
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);
}); 

我不知道为什么。它应该正常工作。

0 个答案:

没有答案