getPhotoUrl()方法中的照片大小Google Identity toolkit

时间:2016-02-13 17:27:28

标签: android google-identity-toolkit google-identity

我使用Google Identity Toolkit登录,我注意到GitkitUser.UserProfile类检索照片网址,但是太小了。谷歌文档没有说明照片大小。

https://developers.google.com/identity/toolkit/android/reference/com/google/identitytoolkit/GitkitUser.UserProfile.html#getPhotoUrl()

例如,使用Facebook登录时,getPhotoUrl()方法会返回:

https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/12651146_10208004779813340_3124516205553866664_n.jpg?oh=efa817d10aaf9d184a767bae81a71071&oe=576850AD

例如,使用Gmail登录时,getPhotoUrl()方法会返回:

https://lh6.googleusercontent.com/-5XFRyKHh7Os/AAAAAAAAAAI/AAAAAAAABIo/Trf7GjTnFec/s96-c/photo.jpg

在Gmail照片网址中删除/ s96-c(或替换为/ s200-c)看起来很大,但我需要对Facebook照片进行解决方法。

2 个答案:

答案 0 :(得分:3)

android的解决方案是获取federatedId并在该调用之后:

http://graph.facebook.com/ {federatedId} /照片?类型=大

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        client = GitkitClient.newBuilder(this, new GitkitClient.SignInCallbacks() {
            @Override
            public void onSignIn(IdToken idToken, GitkitUser user) {
                DataStorage.getInstance().setLastToken(idToken.getTokenString());
                Configuration config = Configuration.fromMetaData(AppInfo.getAppInfo(LoginActivity.this).metaData);
                ApiClient apiClient = new ApiClient(config.getApiKey(), AppInfo.getAppInfo(LoginActivity.this), config.getServerWidgetUrl());
                final GetAccountInfo.Request request = apiClient.newGetAccountInfoRequest(idToken);

                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        GetAccountInfo.Response accountInfo = request.execute();

                        JSONArray users = accountInfo.getJsonResponse().optJSONArray("users");
                        JSONObject user = users == null ? null : users.optJSONObject(0);
                        String email = user == null ? null : user.optString("email");
                        if (email != null) {
                            JSONArray providerUserInfo = user.optJSONArray("providerUserInfo");
                            if (providerUserInfo != null && providerUserInfo.length() != 0) {
                                for (int i = 0; i < providerUserInfo.length(); ++i) {
                                    JSONObject userInfo = providerUserInfo.optJSONObject(i);
                                    if (userInfo != null) {
                                        try {
                                            String userInfoString = userInfo.getString("federatedId");
                                            if(userInfoString.contains("facebook.com")) {
                                                int lastSlash = userInfoString.lastIndexOf("/");
                                                if(lastSlash != -1) {
                                                    String federatedIdFacebook = userInfoString.substring(lastSlash + 1, userInfoString.length());
                                                    Log.i("federatedIdFacebook", federatedIdFacebook);
                                                }
                                                break;
                                            }
                                        } catch (JSONException e) {
                                            Log.e("LoginActivity", e.getMessage());
                                        }
                                    }
                                }
                            }
                        }
                        return null;
                    }
                }.execute();


            }

            @Override
            public void onSignInFailed() {
                Toast.makeText(LoginActivity.this, "Sign in failed", Toast.LENGTH_LONG).show();
            }
        }).build();
    }

答案 1 :(得分:2)

您可以使用idToken在IDP(facebook id)获取用户的标识符。

请参阅[{3}}的用户[]。providerUserInfo []。federatedId

然后使用facebookId获取大帐户图片,

https://developers.google.com/identity/toolkit/web/reference/relyingparty/getAccountInfo {facebookId} /照片?类型=大