获取Facebook相册封面照片 - Android

3
我尝试从Facebook获取相册数据,并使用此方法获取相册封面照片。我得到了以下响应信息:

{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"FACEBOOK_NON_JSON_RESULT":"����\u0000\u0010JFIF\u0000\u0001\u0002\u0000\u0000\u0001\u0000\u0001\u0000\u0000��\u0000�Photoshop"}}, error: null, isFromCache:false}

这是什么意思?我该如何获取图片URL或图片?下面是代码:
   for(final FbAlbumItem f: albums){
        Bundle params = new Bundle();
        params.putString("type", "small");
        new Request(
                Session.getActiveSession(),
                "/"+f.getAlbumId()+"/picture",
                params,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
        /* handle the result */
                        Log.i("SocialManager", "" + response);
                        JSONObject obj = response.getGraphObject().getInnerJSONObject();

                        try {

                          JSONObject o = obj.getJSONObject("albums").getJSONObject("data");
                            String url = o.getString("url");
                           f.setImageUrl(url);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).executeAsync();

FbAlbumItem: 字符串 albumId; 字符串 albumName; 字符串 albumCover; 字符串 imageUrl;


你能展示一下获取数据的代码吗? - Dion V.
更新问题,请检查一下。 - user3053260
3个回答

4
解决了。我使用了我的方法,并进行了一些更改。添加了这个参数。
        Bundle params = new Bundle();
        params.putBoolean("redirect", false);
感谢您的启发。

2

先决条件 - 非公共相册需要user_photos权限

使用cover_photo字段获取它

me/albums/album_id?fields=cover_photo

文档参考 在此处


1
你本来可以像这样做的。
final Session session = Session.getActiveSession();
    if (session.isOpened()) {
        final String authToken = session.getAccessToken();
        // saveToPreferences(ApplicationData.FB_TOKEN, authToken);
        Bundle params = new Bundle();
        params.putBoolean("redirect", false);
        params.putString("height", "400");
        params.putString("type", "normal");
        params.putString("width", "400");
        /* make the API call */
        new Request(
                session,
                "/me/albums/{album-id}",
                params,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
                        //cover_photo_fetch = response.cover_photo.toString();
                        Log.d("Picture", response.toString());
                        try {
                            userModel = UserModel.getInstance(mContext);
                            personPhotoUrl = response.getGraphObject().getInnerJSONObject().getJSONObject("data").getString("url");

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).executeAsync();

谢谢,但是这段代码给我提供的是个人头像。我需要专辑封面照片。我该如何获取它? - user3053260
请查看我的编辑。我根据Facebook文档进行了编辑:https://developers.facebook.com/docs/graph-api/reference/user/albums/ - Ankit Kumar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接