Facebook在没有登录的情况下获得自定义对象的点赞数
Facebook get number of likes on custom object without login
在 Facebook-iOS sdk 的帮助下,我正在使用 og.likes 为我的应用程序中的自定义对象点赞。我可以点赞,也可以阅读。
现在我想知道图表 API 中是否有任何方法可以向未通过 Facebook 登录我们应用程序的用户显示对象的总点赞数?即没有访问令牌
根据 FB 开发者文档:-
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
有人提到您需要查看父对象所需的相同权限才能查看该对象上的赞,这意味着需要具有 read_stream 权限的用户访问令牌。
注意:
但是如果用户想要获得 Facebook 页面或个人资料或对象的点赞数,那么可以通过以下方式轻松完成:-
https://graph.facebook.com/< your object id>/
然后您将收到 json 回复,点赞数:-
{
"id": "12345",
"link": "http://www.facebook.com/pages/MY iOS Page/102445859460201",
"likes": 150,
"type": "page"
}
代码:-
let url = NSURL(string: "http://graph.facebook.com/"+ObjectID)
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in
// Fetch the data
var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
let likesCount = jsonDictionary["likes"] as? String
}
我从
得到了解决方案
How to get Likes Count when searching Facebook Graph API with search=xxx
这里 link 这不是确切的解决方案,但我已经尝试过我的方法,不幸的是它对我有用,我对此非常满意,仍在我的应用程序中使用它。
https://graph.facebook.com/v2.1/{Object-id}?fields=likes.summary(true)
得到 Facebook 团队的回应:
Since Graph API v2.0, all requests to the API require an access token.
You can proxy this request through a web-server and use your app
access token for example.
You could as well make the request from your app by shipping your app
access token with the app, but I highly advise against this as the app
token should be kept secret.
Please note that the SDK does not support using the app access token
for security reasons. So you have to write your own networking code to
fetch this data.
您将需要一个访问令牌,无需登录任何用户,您可以生成一个 APP 访问令牌来获取该信息。
jQuery.get("https://graph.facebook.com/oauth/access_token", {
'grant_type': "client_credentials",
'client_id': "000000000000000",
'client_secret': "0000000000000000000000000000000000"
}, function (data) {
// data is the app access token you will need for calling graph api
});
这更复杂,但解决了用户登录以从图表中获取 public 信息的必要性。
在 Facebook-iOS sdk 的帮助下,我正在使用 og.likes 为我的应用程序中的自定义对象点赞。我可以点赞,也可以阅读。
现在我想知道图表 API 中是否有任何方法可以向未通过 Facebook 登录我们应用程序的用户显示对象的总点赞数?即没有访问令牌
根据 FB 开发者文档:-
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
有人提到您需要查看父对象所需的相同权限才能查看该对象上的赞,这意味着需要具有 read_stream 权限的用户访问令牌。
注意: 但是如果用户想要获得 Facebook 页面或个人资料或对象的点赞数,那么可以通过以下方式轻松完成:-
https://graph.facebook.com/< your object id>/
然后您将收到 json 回复,点赞数:-
{
"id": "12345",
"link": "http://www.facebook.com/pages/MY iOS Page/102445859460201",
"likes": 150,
"type": "page"
}
代码:-
let url = NSURL(string: "http://graph.facebook.com/"+ObjectID)
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in
// Fetch the data
var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
let likesCount = jsonDictionary["likes"] as? String
}
我从
得到了解决方案How to get Likes Count when searching Facebook Graph API with search=xxx
这里 link 这不是确切的解决方案,但我已经尝试过我的方法,不幸的是它对我有用,我对此非常满意,仍在我的应用程序中使用它。
https://graph.facebook.com/v2.1/{Object-id}?fields=likes.summary(true)
得到 Facebook 团队的回应:
Since Graph API v2.0, all requests to the API require an access token. You can proxy this request through a web-server and use your app access token for example.
You could as well make the request from your app by shipping your app access token with the app, but I highly advise against this as the app token should be kept secret.
Please note that the SDK does not support using the app access token for security reasons. So you have to write your own networking code to fetch this data.
您将需要一个访问令牌,无需登录任何用户,您可以生成一个 APP 访问令牌来获取该信息。
jQuery.get("https://graph.facebook.com/oauth/access_token", {
'grant_type': "client_credentials",
'client_id': "000000000000000",
'client_secret': "0000000000000000000000000000000000"
}, function (data) {
// data is the app access token you will need for calling graph api
});
这更复杂,但解决了用户登录以从图表中获取 public 信息的必要性。