【问题标题】:Yelp business ID code with Yelp API使用 Yelp API 的 Yelp 业务 ID 代码
【发布时间】:2018-03-18 02:43:59
【问题描述】:

我有一个 .csv 文件,其中包含我必须使用的 yelp 评论。它为每个用户和企业提供了一个字母数字 ID(可能是评论)。我还没有找到任何方法使用这些代码来定位相关企业的 yelp 页面。代码看起来像这样......

Capriotti 三明治店的“TR0-w6VoZDAdvFQiq7P2Ug”

“pLZ9oZM8c6MNbRlg06lBPg”用于 Impact 汽车玻璃和色调

等等……

我没有关于这些业务的任何其他信息可以使用。我真的很希望能够使用 Yelp 的 API 来查找图像 URL(我已经能够使用),但是没有任何运气将我的 .csv 文件中的信息转换为 API 可以使用的东西。

提前致谢。

【问题讨论】:

    标签: api yelp


    【解决方案1】:

    嘿,我写了这个例子,如果你有一个快速服务器正在运行,你可以粘贴并尝试一下 -

    // using express
    // client - refers to yelp-fusion.client - checkout yelp-fusion NPM
    
    app.get('/reviews', (req, res) => {
      let id = 'TR0-w6VoZDAdvFQiq7P2Ug';
      // id example from your Comment
    
      client.reviews(id).then(response => {
        // find review from ID given in CSV File:
    
        let url = new URL(response.jsonBody.reviews[0].url);
    
        // parse URL using url-parse package, return just pathname
    
        let bizName = url.pathname.substring(5,url.pathname.length);
    
        // every yelp pathname begins with /biz/ - use substring to return only biz name
    
        // now use that bizName to look up business - which will have image url within response:
    
        client.business(bizName)
        .then(response => {
          console.log(response.jsonBody);
          let featuredImgUrl = response.jsonBody.image_url;
          let photos = response.jsonBody.photos;
          res.json(photos)
        });
      }).catch(e => {
        console.log(e);
        res.json('Error');
      });
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多