我试图在没有实施Facebook登录按钮的情况下显示Facebook个人资料图片。我正在使用Facebook SDK。
目前我的个人资料图片如下:
我成功连接到Facebook并使用com.facebook.widget.ProfilePictureView
在xml
现在我在尝试检索个人资料图片的java类中遇到了麻烦:
Game.java
@Override
protected void onCreate(Bundle savedInstanceState) {
...
...
// Find the user's profile picture custom view
profilePictureView = (ProfilePictureView) findViewById(R.id.selection_profile_pic);
profilePictureView.setCropped(true);
// view that in turn displays the profile picture.
profilePictureView.setProfileId(GraphUser.getId()); //eror
...
...
}
错误在于此行:profilePictureView.setProfileId(GraphUser.getId())
在教程中,他们会显示如下的个人资料图片:
@Override
public void onCompleted(GraphUser user, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
if (user != null) {
// Set the id for the ProfilePictureView
// view that in turn displays the profile picture.
profilePictureView.setProfileId(user.getId());
// Set the Textview's text to the user's name.
userNameView.setText(user.getFirstName());
}
}
if (response.getError() != null) {
// Handle errors, will do so later.
}
}
但在我的情况下,我没有登录会话,只想加载快速个人资料照片。所以我尝试用profilePictureView.setProfileId(user.getId());
代替profilePictureView.setProfileId(GraphUser.getId());
,因为user
的类型为GraphUser
编译错误:当我写profilePictureView.setProfileId(GraphUser.getId());
时,它表示无法从GraphUser类型中对非静态方法getId()进行静态引用
有人可以帮我加载我的个人资料照片吗?如果不首先实施Facebook登录,这可能吗?
答案 0 :(得分:2)
在未授权用户的情况下,用户完全是匿名的。所以答案是否定的,你无法在没有登录的情况下显示任何内容,而且你无法在没有登录的情况下获得用户ID(这是获取个人资料图片所需的内容)。用户ID甚至可以让您访问每个用户的真实姓名。当然,未经授权,这是不可能的。
有关登录的更多信息(在Android上):https://developers.facebook.com/docs/android/login-with-facebook/v2.2