【问题标题】:Zomato api is not working in NodejsZomato api 在 Nodejs 中不起作用
【发布时间】:2016-07-02 07:35:18
【问题描述】:

我需要在 Nodejs 中使用 Zomato Api 获取特定餐厅的评论。但是这个 api 在 postman 中工作。

但它在 Nodejs 中不起作用。

app.js

var https = require('https');
var request = require('request');
var zomatoUserKey = '****************************';
var postheaders = {
  'Content-Type': 'application/json; charset=utf-8',
  'user-key': zomatoUserKey
};
var optionspost = {
  host: 'developers.zomato.com', // here only the domain name
  path: 'api/v2.1/reviews', // the rest of the url with parameters if needed
  headers: postheaders,
  method: 'POST',
  data: '{"res_id": "zoma.to/r/34343"}'
};
https.request(optionspost, function(error, response, body) {
  console.log('error', error);
  console.log('body', body);
  console.log('response', response);
});

【问题讨论】:

    标签: javascript node.js express request zomato-api


    【解决方案1】:

    根据documentation of Zomato API,您需要使用GET 请求而不是POST

    var optionspost = {
      host: 'developers.zomato.com', // here only the domain name
      path: '/api/v2.1/reviews', // the rest of the url with parameters if needed
      headers: postheaders,
      method: 'GET',
      // -------^----
      data: '{"res_id": "zoma.to/r/34343"}'
    };
    

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2017-12-22
      • 1970-01-01
      • 2020-10-11
      相关资源
      最近更新 更多