不登录显示个人资料图片
Show Profile Picture without Login
我想在不实现 Facebook 登录按钮的情况下显示 Facebook 个人资料图片。我正在使用 Facebook SDK。
目前我的头像是这样的:
我成功连接到 Facebook 并使用 com.facebook.widget.ProfilePictureView
在 xml
中显示一张空的头像
现在我在 java class 尝试检索我的个人资料图片时遇到问题:
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
对 non-static 方法 getId() 进行静态引用
有人可以帮我加载我的个人资料照片吗?如果不先实施 Facebook 登录,这可能吗?
没有授权用户,用户是完全匿名的。所以答案是否定的,没有登录你就不能显示任何东西,而且你当然不能在没有登录的情况下获得用户 ID(这是获得个人资料图片所需要的)。用户 ID 甚至可以让您访问每个用户的真实姓名。当然,未经授权这是不可能的。
有关登录的更多信息(在 Android):https://developers.facebook.com/docs/android/login-with-facebook/v2.2
我想在不实现 Facebook 登录按钮的情况下显示 Facebook 个人资料图片。我正在使用 Facebook SDK。
目前我的头像是这样的:
我成功连接到 Facebook 并使用 com.facebook.widget.ProfilePictureView
在 xml
现在我在 java class 尝试检索我的个人资料图片时遇到问题:
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
有人可以帮我加载我的个人资料照片吗?如果不先实施 Facebook 登录,这可能吗?
没有授权用户,用户是完全匿名的。所以答案是否定的,没有登录你就不能显示任何东西,而且你当然不能在没有登录的情况下获得用户 ID(这是获得个人资料图片所需要的)。用户 ID 甚至可以让您访问每个用户的真实姓名。当然,未经授权这是不可能的。
有关登录的更多信息(在 Android):https://developers.facebook.com/docs/android/login-with-facebook/v2.2