我在显示我的Facebook图片和名称时遇到问题。我无法找到正确的方法。我在Facebook的登录按钮工作正常。
我收到此错误:profilePictureView.setProfileId(profile.getId());错误NULL
public class Profile extends Activity {
/**
* Called when the activity is first created.
*/
WebView web;
ArrayList<NavigationDrawerItem> listItems;
DrawerLayout drawerLayout;
ActionBarDrawerToggle drawerToggle;
ListView list;
private CallbackManager callbackManager;
private ProfilePictureView profilePictureView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_profile);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("public_profile", "email", "user_friends");
final ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.profilepic);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
profilePictureView.setProfileId(profile.getId());
Intent i = new Intent(Profile.this, Profile.class);
startActivity(i);
System.out.print("Logged in");
}
public final void getProfileId(){
Log.i("profileId", "Your profileId");
}
public final void setProfileId(String profileId) {
Log.i("profileId", "Your profileID");
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
Log.i("Error", "Error");
}
});
我的XML文件显示无用户图像。但不是我的。
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/welcome_profile_pic"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
facebook:preset_size="small" />
答案 0 :(得分:0)
首先找我告诉我你可能错过了
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
答案 1 :(得分:0)
删除内部的Intent:onSuccess。这解决了我的问题。