照片大小getPhotoUrl()方法谷歌标识​​的工具包 [英] Photo size in getPhotoUrl() method Google Identity toolkit

查看:488
本文介绍了照片大小getPhotoUrl()方法谷歌标识​​的工具包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用谷歌标识工具包登录,我已经注意到,类GitkitUser.UserProfile检索图片的URL,但太小了。在谷歌文档不说关于照片大小事情。

I did the login using Google Identity Toolkit, I have noticed that the class GitkitUser.UserProfile retrieves the photo url, but is too small. The google documentation do not say anything about photo size.

<一个href=\"https://developers.google.com/identity/toolkit/android/reference/com/google/identitytoolkit/GitkitUser.UserProfile.html#getPhotoUrl()\" rel=\"nofollow\">https://developers.google.com/identity/toolkit/android/reference/com/google/identitytoolkit/GitkitUser.UserProfile.html#getPhotoUrl()

例如与Facebook登录,getPhotoUrl()方法返回:

<一个href=\"https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/12651146_10208004779813340_3124516205553866664_n.jpg?oh=efa817d10aaf9d184a767bae81a71071&oe=576850AD\" rel=\"nofollow\">https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/12651146_10208004779813340_3124516205553866664_n.jpg?oh=efa817d10aaf9d184a767bae81a71071&oe=576850AD

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

<一个href=\"https://lh6.googleusercontent.com/-5XFRyKHh7Os/AAAAAAAAAAI/AAAAAAAABIo/Trf7GjTnFec/s96-c/photo.jpg\" rel=\"nofollow\">https://lh6.googleusercontent.com/-5XFRyKHh7Os/AAAAAAAAAAI/AAAAAAAABIo/Trf7GjTnFec/s96-c/photo.jpg

删除/ S96-C(或替换到/ S200-C)在Gmail中的照片网址出现大了,但我需要一个解决办法Facebook的照片。

Deleting /s96-c (or replace to /s200-c) in the Gmail photo url appears big, but I need a workaround to Facebook photo.

我试图找到一个更好的解决方案。任何想法将AP preciated。

I am trying to find a better solution. Any idea will be appreciated.

在先进的感谢。

推荐答案

针对Android的解决方案是获得federatedId和调用后:

The solution for android was obtain the federatedId and after that call:

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

http://graph.facebook.com/{federatedId}/picture?type=large

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();
    }

这篇关于照片大小getPhotoUrl()方法谷歌标识​​的工具包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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