-2
我做我的博士工作致力於社交網絡分析。 當工具被選中Node JS和Facebook API 現在我可以做的是檢索用戶的ID與額外的信息,但要建立圖我需要用戶的朋友列表。 我有Heroku應用程序,但我完全失望怎麼用te APP_ID來獲取構建數據所需的信息。 我應該從哪裏開始?檢索特定用戶ID的信息
我做我的博士工作致力於社交網絡分析。 當工具被選中Node JS和Facebook API 現在我可以做的是檢索用戶的ID與額外的信息,但要建立圖我需要用戶的朋友列表。 我有Heroku應用程序,但我完全失望怎麼用te APP_ID來獲取構建數據所需的信息。 我應該從哪裏開始?檢索特定用戶ID的信息
有一些Node.js包可用於此目的。
This是非常有用的,如果你想要寫你的服務器(的NodeJS)之間的相同的代碼和共享與客戶端(FB JS-SDK)
爲了開始,你需要有來自用戶的access_tokens,你想要的信息。 (通過FB APP)
FB.login(function(response) {
if (response.authResponse) {
var res = response.authResponse;
FB.api('/me', function(response) {
registerUser({ "fb_user_id": res.userID, //register user in your database
"access_token": res.accessToken
}, function() {
//handle here after registration
});
});
} else {
//handle reject in requested fields
}
}, { scope: 'email,friends_about_me'});
//you can set scope field according to your use.
參見this爲可在範圍字段中使用擴展的配置文件屬性。
一旦你獲得了access_tokens,你可以在上面的第三方SDK中使用它們。
該SDK還提供您請求API的access_token
var FB = require('fb');
var accessToken = FB.getAccessToken();
FB.setAccessToken(accessToken);
FB.api('idHere', { fields: ['id', 'name'] }, function (res) { //you can access fields, access_token has access to
if(!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(res.id);
console.log(res.name);
});
您還可以用直接的access_token使用api function
。
FB.api('me', { fields: ['id', 'name'], access_token: 'access_token' }, function (res) {
console.log(res);
}
謝謝!這個例子讓我們獲得了我已經擁有的公共信息。但獲得我必須擁有access_token的朋友列表。如何獲得這個令牌? – user2241943 2013-04-04 06:51:54