问题
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.
https://developers.google.com/identity/toolkit/android/reference/com/google/identitytoolkit/GitkitUser.UserProfile.html#getPhotoUrl()
For example with Facebook login, the getPhotoUrl() method returns:
https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/12651146_10208004779813340_3124516205553866664_n.jpg?oh=efa817d10aaf9d184a767bae81a71071&oe=576850AD
For example with Gmail login, the getPhotoUrl() method returns:
https://lh6.googleusercontent.com/-5XFRyKHh7Os/AAAAAAAAAAI/AAAAAAAABIo/Trf7GjTnFec/s96-c/photo.jpg
Deleting /s96-c (or replace to /s200-c) in the Gmail photo url appears big, but I need a workaround to Facebook photo.
回答1:
The solution for android was obtain the federatedId and after that call:
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();
}
回答2:
You could use the idToken to get the User's identifier at IDP (facebook id).
See users[].providerUserInfo[].federatedId at https://developers.google.com/identity/toolkit/web/reference/relyingparty/getAccountInfo
And then use the facebookId to get the large account picture, with
http://graph.facebook.com/{facebookId}/picture?type=large
来源:https://stackoverflow.com/questions/35382965/photo-size-in-getphotourl-method-google-identity-toolkit