[英]Name and profile picture from Facebook into Android app
I'm having problems displaying my Facebook picture and name. 我在显示我的Facebook图片和名称时遇到问题。 I can't figure out the right way to do it. 我想不通正确的方法。 My login button with Facebook works fine. 我的Facebook登录按钮运行正常。
I got this Error: profilePictureView.setProfileId(profile.getId()); 我收到此错误:profilePictureView.setProfileId(profile.getId()); Error NULL 错误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");
}
});
My XML file shows the no user image. 我的XML文件显示无用户图像。 But not mine. 但不是我的。
<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" />
First look for me tells me that you might be missing the 首先找我告诉我,您可能会想念
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
Removed the inside Intent inside: onSuccess. 删除了内部的Intent内部:onSuccess。 This solved my problem. 这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.