[英]Android Facebook Like Button
Is it possible that I place a like button on my android app clicking which likes a post which is publicly available on facebook? 我是否有可能在我的android应用程序上单击一个喜欢的按钮,从而喜欢在Facebook上公开可用的帖子? I do not want any additional windows to open for the task except may be for first time authentication. 除了可能是首次身份验证之外,我不希望为该任务打开任何其他窗口。
All questions asked so far are related to opening a new window. 到目前为止,所有提出的问题都与打开新窗口有关。
It is possible. 有可能的。 You can perform a Like Action using Facebook's Open Graph API. 您可以使用Facebook的Open Graph API执行“喜欢”操作。 In order to do so, you need to meet certain conditions: 为此,您需要满足某些条件:
Steps at a high-level: 高层步骤:
You need to first get the user's active Session
( com.facebook.Session
). 您需要首先获取用户的活动Session
( com.facebook.Session
)。
Session session = Session.getActiveSession();
Then you need to ensure that the user has the publish_actions
permission. 然后,您需要确保用户具有publish_actions
权限。 If not, request them. 如果没有,请提出要求。
List<String> requestedPermissions = Arrays.asList("publish_actions");
List<String> currentPermissions = session.getPermissions();
if (!currentPermissions.containsAll(requestedPermissions)) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, requestedPermissions);
session.requestNewPublishPermissions(newPermissionsRequest);
}
Finally, send your request to "me/og.likes"
. 最后,将您的请求发送到"me/og.likes"
。 Your request should include your Session
, a Bundle
including the Graph object you want to like, the HTTP method, and a callback that will execute once you receive a response. 您的请求应包括您的Session
,包含您想要的Graph对象的Bundle
,HTTP方法以及将在收到响应后执行的回调。
Bundle postParams = new Bundle();
postParams.putString("object", myGraphObject);
Request request = new Request(session, "me/og.likes", postParams, HttpMethod.POST, myCallback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
You want to perform these steps in your button's OnClickListener
. 您想在按钮的OnClickListener
执行这些步骤。
Hope this helps! 希望这可以帮助!
Resources: 资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.