简体   繁体   English

Android Facebook赞按钮

[英]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: 为此,您需要满足某些条件:

  1. The viewer of the in-app content is a Facebook user who has Facebook-authed and granted the app publish_actions permission 应用内内容的查看者是具有Facebook身份验证并授予应用publish_actions权限的Facebook用户
  2. The in-app content has an Open Graph object page that is properly marked-up using Open Graph metatags 应用内内容具有一个“打开图”对象页面,该页面已使用“打开图”元标记进行了正确标记
  3. The viewer has intentionally clicked on a custom in-app “like button” associated with the in-app content 观看者有意点击了与应用内内容相关联的自定义应用内“赞按钮”

Steps at a high-level: 高层步骤:

You need to first get the user's active Session ( com.facebook.Session ). 您需要首先获取用户的活动Sessioncom.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: 资源:

Like Action 喜欢动作

Publishing Conditions 发布条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM