首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >似乎无法获取facebook好友的照片?

似乎无法获取facebook好友的照片?
EN

Stack Overflow用户
提问于 2015-11-10 17:08:02
回答 1查看 191关注 0票数 0

我正在尝试通过Graph API获取我的Facebook朋友的照片。这是我的尝试:

代码语言:javascript
运行
复制
public void getFacebookData(final AccessToken accessToken){
    //newMeRequest = My own data
    //myFriendsRequest = my mutual friends who have the app downloaded
    //Basically make 2 requests to one's Facebook info and return the names, links, id, and picture of the individual

    AccessToken accesstoken = AccessToken.getCurrentAccessToken();

    JSONArray friends = new JSONArray();
    GraphRequestBatch batch = new GraphRequestBatch(
            GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(
                                JSONObject jsonObject,
                                GraphResponse response) {
                            // Application code for user                            
                        }
                    }),
            GraphRequest.newMyFriendsRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONArrayCallback() {
                        @Override
                        public void onCompleted(JSONArray jsonArray,
                                                GraphResponse response) {
                            // Application code for users friends
                            // Insert into our local DB
                            Toast.makeText(login.this, "" + response.toString(), Toast.LENGTH_SHORT).show();
                            try {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject row = jsonArray.getJSONObject(i);
                                    System.out.println("Got id");
                                    datasource.createFriend(row.getString("name"), row.getString("id"));
                                    new GraphRequest(
                                            AccessToken.getCurrentAccessToken(),
                                            "/" + row.getString("id") + "/picture",
                                            null,
                                            HttpMethod.GET,
                                            new GraphRequest.Callback() {
                                                public void onCompleted(GraphResponse response) {
                                                    System.out.println("Got photo");
                                                }
                                            }
                                    );
                                }
                            } catch (JSONException e) {
                                throw new RuntimeException(e);
                            }
                            System.out.println("FriendsDB: " + jsonArray);
                        }
                    }
            )
    );
    batch.addCallback(new GraphRequestBatch.Callback() {
        @Override
        public void onBatchCompleted(GraphRequestBatch graphRequests) {
            // Application code for when the batch finishes
            Log.d(TAG, graphRequests.toString());

        }
    });
    batch.executeAsync();

然而,问题是我似乎永远不能打印"Got Photo"消息。我之所以感到困惑,是因为我查看了GraphRequest构造函数,发现这个方法最适合我。然而,这个方法永远不会完成,我真的不确定它为什么会失败。任何帮助都将不胜感激。谢谢!

编辑:我已经确保我有在我的应用上通过身份验证的freinds,并具有以下权限:

loginButton.setReadPermissions(Arrays.asList("user_friends", "public_profile", "email"));

EN

回答 1

Stack Overflow用户

发布于 2015-11-10 17:42:23

我认为您正在尝试获取登录用户的所有好友,从Graph API v2中,您不会通过调用USER_ID/friends来获取好友列表。现在,这将返回使用该应用程序或已授权自己访问特定facebook应用程序的用户的朋友。

有关这方面的详细信息,请访问here

关于用户的照片,请阅读文档here

编辑1个

对于个人资料图片,从图形API中获取用户id,并

在xml文件中添加ProfilePictureView

代码语言:javascript
运行
复制
    <com.facebook.widget.ProfilePictureView
   android:id="@+id/friendProfilePicture"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:gravity="center_horizontal"
   android:padding="5sp"
   facebook:preset_size="small" />

现在从Java添加用户的id,如下所示:-

代码语言:javascript
运行
复制
ProfilePictureView profilePictureView;
profilePictureView = (ProfilePictureView) findViewById(R.id.friendProfilePicture);
profilePictureView.setProfileId(userId);

使用Picasso获取图像,并使用此链接将其添加到ImageView

代码语言:javascript
运行
复制
https://graph.facebook.com/{facebookId}/picture?type=large
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33626313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档