【问题标题】:Name and profile picture from Facebook into Android app从 Facebook 到 Android 应用程序的姓名和个人资料图片
【发布时间】:2015-06-04 08:55:41
【问题描述】:

我在显示我的 Facebook 图片和姓名时遇到问题。我想不出正确的方法来做到这一点。我的 Facebook 登录按钮工作正常。

我收到此错误:profilePictureView.setProfileId(profile.getId());错误为空

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" />

【问题讨论】:

  • 去掉了intent inside:onSuccess

标签: java android facebook-sdk-4.0


【解决方案1】:

First look for me 告诉我你可能错过了

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

}

【讨论】:

  • 它就在那里 - 我只是在发布之前拿走了一些代码。
【解决方案2】:

去掉了intent里面的intent:onSuccess。这解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 2015-03-08
    • 2014-01-04
    • 2014-06-21
    • 1970-01-01
    相关资源
    最近更新 更多