从Facebook到Android应用的名称和个人资料图片

问题描述 投票:0回答:2

我在显示我的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" />
java android facebook-sdk-4.0
2个回答
0
投票

首先找我告诉我,您可能会想念

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

}

0
投票

删除了内部的Intent内部:onSuccess。 这解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.