我希望用户从我的Android应用程序中喜欢我的Facebook粉丝页面, 怎么做 下面是我的代码
318093631634608是任何页面; 许可清单
private static final List<String> PERMISSIONS = Arrays
.asList("page_fan","publish_actions" ,"user_likes","friends_likes","manage_pages","publish_stream","user_status", "user_online_presence", "friends_online_presence");
private void likePage()
{
Session session = Session.getActiveSession();
if (session != null)
{
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Request likeRequest = new Request(Session.getActiveSession(), "318093631634608" + "/likes", null, HttpMethod.POST, new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(Facebook.this,
error.getErrorMessage(), Toast.LENGTH_SHORT)
.show();
Log.i("error like", error.getErrorMessage().toString());
} else {
Log.i("user id", "success page liked");
Toast.makeText(Facebook.this, "success loked the page",
Toast.LENGTH_LONG).show();
}
}
});
Request.executeBatchAsync(likeRequest);
}
}
logcat的
12-03 22:31:04.512: W/com.facebook.Session(16294): Should not pass a read permission (page_fan) to a request for publish or manage authorization
12-03 22:31:04.519: W/com.facebook.Session(16294): Should not pass a read permission (user_likes) to a request for publish or manage authorization
12-03 22:31:04.519: W/com.facebook.Session(16294): Should not pass a read permission (friends_likes) to a request for publish or manage authorization
12-03 22:31:04.519: W/com.facebook.Session(16294): Should not pass a read permission (user_status) to a request for publish or manage authorization
12-03 22:31:04.519: W/com.facebook.Session(16294): Should not pass a read permission (user_online_presence) to a request for publish or manage authorization
12-03 22:31:04.519: W/com.facebook.Session(16294): Should not pass a read permission (friends_online_presence) to a request for publish or manage authorization
有一段时间它显示出来 应用程序无权在android
中进行此调用答案 0 :(得分:0)
无法以编程方式浏览页面,只能评论评论和帖子。但是为了喜欢facebook上的帖子,我使用这部分代码来创建请求。
Request likeRequest = new Request(Session.getActiveSession(), pageid + "/likes", null, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
}
});
希望这有帮助..