我有一个网站并使用facebook登录。 我想做以下事情:
用户访问我的网站 - 使用Facebook登录 - 我阅读了他的Facebook数据和摄影许可证
例如:
{
"id": "1"
"name": "John English"
"first_name": "John",
"last_name": "English"
"link": "https://www.facebook.com/johnenglish"
"username": "johnenglish"
"gender": "male"
"locale": "en_US"
....
}
和
{
"id": "2"
"name": "John English2"
"first_name": "John",
"last_name": "English2"
"link": "https://www.facebook.com/johnenglish2"
"username": "johnenglish2"
"gender": "male"
"locale": "en_US"
....
}
两位用户都有私人照片。我可以使用javascript从我的网络应用程序加载用户(id:2)的私人照片吗?你能举个例子吗?
我试过这个:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/USER-ID(USER ID 2)/photos?access_token=' + accessToken, function(response) {
//A user access token is required to request this resource.
});
} else if (response.status === 'not_authorized') {
} else {
}
});
错误:请求此资源需要用户访问令牌。
答案 0 :(得分:1)
获得访问令牌时是否请求了正确的权限?我不知道如何在JS中这样做,但你必须告诉facebook,你希望你能够访问这些照片。由于我不使用JS,我通过URL请求访问令牌(请参阅此处的第1点:https://developers.facebook.com/docs/authentication/devices/)。在参数“scope”中,您可以添加要拥有的权限(https://developers.facebook.com/docs/authentication/permissions/)。在这里,您将“& scope = user_photos”(不带引号)添加到URL。
答案 1 :(得分:-1)
好的,现在我理解你的问题。
我假设您已经找到了用户2的ID。很抱歉,我仍然无法向您展示如何在JS中执行此操作。虽然,它可能有所帮助。
首先,我忘记了一个权限,您在范围内也需要friends_photos
。
您现在致电:http://graph.facebook.com/FRIEND_ID/albums/?access_token=ACCESS_TOKEN。
在浏览器中输入,以便您知道我的意思:您解析该输出并查找朋友专辑的ID。
您可以通过http://graph.facebook.com/ALBUM_ID?access_token=ACCESS_TOKEN访问该相册。
您会在输出中找到名为cover_photo
的条目。
致电:http://graph.facebook.com/COVER_PHOTO_ID?access_token=ACCESS_TOKEN,即可访问该照片。
您现在可以通过http://graph.facebook.com/COVER_PHOTO_ID/picture?access_token=ACCESS_TOKEN下载它。
使用paging
中指定的网址 - > next
继续查看以下照片。考虑到here,可以更容易地按照这些步骤进行操作。