无法使用node.js与Facebook的graphicsAPI进行交互
这是我试图打的url:
https://graph.facebook.com/v2.8/me?fields=friends?access_token=xxxx.
预期结果:(如图表API资源pipe理器):
{ "friends": { "data": [ ], "summary": { "total_count": 648 } }, "id": "xxxx" }
打电话给朋友的号码:(node.js)
fb.getFbData(constants.AccessToken, 'me?fields=friends', function(data){ res.send(data); });
取数的朋友的方法:(node.js)
var https = require('https'); exports.getFbData = function(accessToken, apiPath, callback) { var options = { host: 'graph.facebook.com', port: 443, path: apiPath + '?access_token=' + accessToken, //apiPath example: '/me/friends' method: 'GET' }; console.log("\n\n options:::", options); var buffer = ''; //this buffer will be populated with the chunks of the data received from facebook var request = https.get(options, function(result){ result.setEncoding('utf8'); result.on('data', function(chunk){ buffer += chunk; }); result.on('end', function(){ callback(buffer); }); }); request.on('error', function(e){ console.log('error from facebook.getFbData: ' + e.message) }); request.end(); }
错误:
有两件事错了:
-
不正确的url,正在传递的第二个参数在URL中没有“&”。
-
当像这样的调用使用https.get和'options'时:
var options = {host:'graph.facebook.com',port:443,path:apiPath +'?access_token ='+ accessToken,method:'GET'};
然后,“主机”被附加到URL中,因此“path”只需要包含网站上的目录。 例如:/v2.8/me?fields=friends
- 节点/ Angular / Passport / Satellizer基于令牌的Facebook身份validation不返回令牌
- 500(内部服务器错误)JavaScript,parsing,快速发布请求
- Android Facebooklogin和服务器端身份validation
- 在PhoneGap应用上执行授权(通过脸书)REST请求到我的node.js服务器
- Mongoose schematype.castForQuery错误。 用户身份validation失败
- 如何将Facebook SDK集成到节点js?
- 对没有调用callback的NodeJS函数进行摩卡testing
- 如何解决,如果EAI_AGAIN错误发生在Facebook Messenger平台上?
- 我在哪里可以find一个简单的Node.js Facebook应用程序示例?