我第一次将Facebook sdk集成到我的Android应用程序中......我在将我的脸谱资料图片放入我的应用程序时遇到了一些问题。
这是onSuccess回调方法:
public void onSuccess(LoginResult loginResult) {
Profile profile = Profile.getCurrentProfile();
if(profile != null) {
Log.v("Logged In Message", profile.getName());
imageView.setImageURI(profile.getProfilePictureUri(50, 50));
}
}
问题是我得到了正确的名字,但没有得到个人资料图片......
任何帮助将不胜感激
答案 0 :(得分:1)
您无需拥有个人资料图片。您可以通过它的唯一ID调用uid来获取用户个人资料图片,如下所示
http://graph.facebook.com/451985168296158/picture?width=150&height=150
答案 1 :(得分:1)
代码示例
loginManager.logInWithReadPermissions(SocialPluginMainActivity.this, permissionNeeds);
loginManager.registerCallback(fbCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
Log.v("LoginActivity", response.toString());
try {
fbUserId = object.getString("id");
fbUserName = object.getString("name");
fbEmail = object.getString("email");
fbGender = object.getString("gender");
fbDob = object.getString("birthday");
} catch (JSONException e) {
e.printStackTrace();
}
Glide.with(SocialPluginMainActivity.this).load("http://graph.facebook.com/" +fbUserId +"/picture?type=large").into(profilePicImgView);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});