使用Facebook应用程序范围的ID进行ProfilePictureView [英] Use Facebook App-scoped Id for ProfilePictureView

查看:104
本文介绍了使用Facebook应用程序范围的ID进行ProfilePictureView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个Android应用程序实现facebook的SDK.我有一个ProfilePictureView,需要填写:

I am implementing facebook's SDK for an android app. I have a ProfilePictureView, that requires, to be filled:

profilePictureView.setProfileId(id)

昨天,如果我使用配置文件的应用程序范围的ID(由Graph API返回的ID),它会起作用:这是我唯一的ID,因为显然违反了Facebook的政策来获取真实" ID.

Yesterday, if I used the App-scoped Id of the profile (the one returned by Graph API) it worked: that's the only id I have, because apparently is against Facebook policy to get the "real" id.

但是今天,它未经任何修改就返回了空图像.我猜想他们改变了后端,但是如果这样,ProfilePictureView的目的是什么,如果它需要一个与Facebook的政策背道而驰的ID?

But today, without any modification, it returns a null image. I am guessing they changed the backend, but if so, what is the purpose of ProfilePictureView if it requires an id that is against Facebook's policy to get?

推荐答案

从2018年3月26日起,与手动链接相关的所有解决方案将不再起作用

使用下面的代码

private static String FACEBOOK_FIELD_PROFILE_IMAGE = "picture.type(large)";
    private static String FACEBOOK_FIELDS = "fields";

    private void getFacebookData() {
        GraphRequest request = GraphRequest.newMeRequest(
                AccessToken.getCurrentAccessToken(),
                (object, response) -> {
                    updateAvatar(getImageUrl(response));
                });
        Bundle parameters = new Bundle();
        parameters.putString(FACEBOOK_FIELDS, FACEBOOK_FIELD_PROFILE_IMAGE);
        request.setParameters(parameters);
        request.executeAsync();
    }

    private static String FACEBOOK_FIELD_PICTURE = "picture";
    private static String FACEBOOK_FIELD_DATA = "data";
    private static String FACEBOOK_FIELD_URL = "url";
    private String getImageUrl(GraphResponse response) {
        String url = null;
        try {
            url = response.getJSONObject()
                    .getJSONObject(FACEBOOK_FIELD_PICTURE)
                    .getJSONObject(FACEBOOK_FIELD_DATA)
                    .getString(FACEBOOK_FIELD_URL);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return url;
    }

这篇关于使用Facebook应用程序范围的ID进行ProfilePictureView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆