【问题标题】:Facebook auth with firebase get User dataFacebook auth with firebase 获取用户数据
【发布时间】:2018-12-16 21:40:35
【问题描述】:

我正在尝试通过 Facebook 使用 Firebase 身份验证。

我已经成功实现了登录部分,但在使用 accessToken 从 facebook 获取用户详细信息时卡住了。

代码如下:

loginButton.setReadPermissions("email", "public_profile"    );
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(final LoginResult loginResult) {
                Log.d(TAG, "facebook:onSuccess:" + loginResult);
                GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject me, GraphResponse response) {
                                Log.e("FBRESPONSE",me.toString());
                                if (response.getError() != null) {
                                    // handle error
                                } else {
                                    if (me.has("picture")) {
                                        try {
                                            f_photo = me.getJSONObject("picture").getJSONObject("data").getString("url");
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                    f_email = me.optString("email");
                                    String id = me.optString("id");
                                    f_name=me.optString("first_name")+" "+me.optString("last_name");;
                                    handleFacebookAccessToken(loginResult.getAccessToken());
                                }
                            }
                        }).executeAsync();
            }
        });

这是我调用它时得到的 JSON 响应。

E/FBRESPONSE: {"name":"Vishnu Reddy","id":"855235691328214"}

我如何获得电子邮件、个人资料图片 URL?

请帮忙。提前致谢。

【问题讨论】:

    标签: android firebase facebook-graph-api firebase-authentication facebook-login


    【解决方案1】:

    您需要使用Facebook Graph API。您需要让您的用户登录并拨打AccessToken.refreshCurrentAccessTokenAsync(); 并向您需要的用户数据字段发起请求。

    【讨论】:

    • 谢谢。这行得通。但是如何获取头像URL呢?
    • @mavillavishnuvardhan https://graph.facebook.com/{userFacebookID}/picture?type=large
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 2011-07-21
    • 2020-01-01
    相关资源
    最近更新 更多