Facebook喜欢按钮+ Phonegap [英] Facebook Like button + Phonegap

查看:126
本文介绍了Facebook喜欢按钮+ 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!


  • 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.


  • 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.


  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆