繁体   English   中英

Zomato API在Node.js中不起作用

[英]Zomato api is not working in Nodejs

我需要使用Nodejs中的Zomato Api对特定餐厅进行评论 。但是此api在邮递员中工作。

邮递员回应

但是它在Nodejs不起作用

Node.js响应 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);
});

根据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"}'
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM