Facebook喜欢按钮+ Phonegap [英] Facebook Like button + Phonegap
问题描述
我想在我的Phonegap(HTML + JS)应用程序中使用Facebook Like按钮,但它不工作。
I'm trying to use Facebook Like button in my Phonegap (HTML + JS) app, but it doesn't work.
但是当我用Phonegap BUild构建它并在智能手机上运行时,该按钮不显示。
But when I build it with Phonegap BUild and run it in my smartphone, the button is not showed.
我使用下面的代码:
<div class="fb-like" data-href="https://www.facebook.com/pages/Save-Points/293951217439051" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
推荐答案
当前实现类似操作的方法是使用打开图形对象 og.like
- FB的文档这里。重要的是要注意,这个方法需要用户的 publish_actions
权限。
The current way to implement the like action is by using the open graph object og.like
- FB's documentation here. It's important to note that this method requires the publish_actions
permission from the user. It's a bit of work to get this all running smoothly, but it is possible.
phonegap-facebook-plugin 已提供指南此处。以下是我的部分评论的说明:
The phonegap-facebook-plugin has provided a guide here. Below are the instructions with some of my comments:
- 您喜欢的按钮不能是相同的作为Facebook喜欢的按钮
这意味着没有竖起符号 - / p>
This means no "thumbs up" symbol - quite a frustration!
- 当您显示页面/按钮时,必须首先调用getLoginStatus方法来了解当前用户是连接到其Facebook帐户。如果他已连接,请调用GET https://graph.facebook。 com / me / og.likes?access_token = FB_ACCESS_TOKEN& object = URL_TO_LIKE 与由g3返回的Facebook访问令牌。 etAccessToken方法(如果这样返回数据,那么用一个红色的心形成你的like按钮,例如,如果调用返回一个空数组,灰色的心。)
- When you display your page / button you have to call the getLoginStatus method first to know if the current user is connected to its Facebook account. If he is connected then call GET https://graph.facebook.com/me/og.likes?access_token=FB_ACCESS_TOKEN&object=URL_TO_LIKE with the Facebook Access Token returned by the g3. etAccessToken method (if this returns data then style your like button with a red heart for example, a grey heart if the call returns an empty array).
除了检查用户是否登录之外,重申您必须检查您的应用程序是否具有用户的 publish_actions
权限。
Along with checking a user is logged in, to reiterate you must check your app has publish_actions
permission for the user. Though you could possibly request this upon the Like action.
此外,数组位于 data
属性中。响应对象。如果你检查用户是否喜欢这个URL,你基本上想检查 response.data.length> 0
。
Also, the array is in the data
property of the response object. If you're checking as to whether the user has liked this URL, you'll basically want to check response.data.length > 0
.
- 要创建类似的按钮和您喜欢的按钮是灰色的心)在 https上执行POST ://graph.facebook.com/me/og.likes?access_token = FB_ACCESS_TOKEN& object = URL_TO_LIKE 注意:您必须具有publish_actions权限才能执行此操作
- To create a like (when your user clicks on your like button and your like button is a grey heart) do a POST on https://graph.facebook.com/me/og.likes?access_token=FB_ACCESS_TOKEN&object=URL_TO_LIKE NOTE: You must have publish_actions permission to do this
完成后,用户已成功地接受了URL,现在 GET
返回一个对象的数组。
After doing this, the URL has been successfully liked by the user, and now the GET
method will return an array with one object. Calling this when the user already has liked the URL will result in an error.
- 若要删除类似(当您的用户点击您喜欢的按钮,而您喜欢的按钮是红色的心),请在 https: //graph.facebook.com/LIKE_IDENTIFIER?access_token=FB_ACCESS_TOKEN 。 LIKE_IDENTIFIER从步骤2或3返回。
- To remove a like (when your user clicks on your like button and your like button is a red heart) do a DELETE on https://graph.facebook.com/LIKE_IDENTIFIER?access_token=FB_ACCESS_TOKEN. The LIKE_IDENTIFIER is returned from steps 2 or 3.
DELETE )方法不同于其他 - 它不基于 / me
,而不是通过URL过滤,你使用like id。您可能必须调用上述 GET
方法来获取ID(do response.data [0] .id
)。
The unlike (DELETE
) method is different to the rest - it's not based off /me
, and instead of filtering via URL, you use the like id. You'll likely have to call the previously described GET
method to get the ID (do response.data[0].id
).
这篇关于Facebook喜欢按钮+ Phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!