我试图获取给定网址的google plus共享计数,我可以在客户端使用jquery使其工作,但现在我尝试使用nodejs在服务器端执行此操作。
例如在jquery中,我会使用它:
$.ajax({
cache: false,
type: "POST",
url: "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",
data: [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"http://www.test.com","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}],
dataType: "jsonp",
success: function (data) {
console.log(data);
},
error: function(data){
console.log(data);
}
})
我想在nodejs上使用请求模块做同样的事情:
request.post(
'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ',
{ form: [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"http://www.paulgraham.com","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}] },
function (error, response, body) {
console.log(response.statusCode)
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
我似乎无法弄明白。我收到415
错误。