我试图显示一个Facebook的个人资料图片,而没有实现Facebook登录按钮。我正在使用Facebook。
目前,我的个人资料图片如下:

我成功地连接到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登录,这是可能的吗?
发布于 2015-01-12 20:44:18
在不授权用户的情况下,用户是完全匿名的。所以答案是否定的,没有登录就不能显示任何东西,当然没有登录就无法获得用户ID (这就是获取配置文件图片所需要的)。用户ID甚至允许您访问每个用户的真实名称。当然,如果没有授权,那是不可能的。
关于登录(安卓)的更多信息:https://developers.facebook.com/docs/android/login-with-facebook/v2.2
https://stackoverflow.com/questions/27910215
复制相似问题