2

I am using og.likes to like custom object from my app, with the help of Facebook-iOS sdks. I am able to like object and also read the like.

Now I want to know if there is any way in graph API that, I can show total number of likes on an object to a user who is not logged in to our app via Facebook ? i.e without access token

Haris
  • 1,822
  • 2
  • 22
  • 44

4 Answers4

1

As per FB developer docs:-

https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes

It is mentioned that you need the same permissions required to view the parent object are required to view likes on that object, means an user access token with read_stream permission is required.

NOTE: But if a user want to get the no of likes for Facebook page or profile or object , then it can be easily done by this:-

https://graph.facebook.com/< your object id>/

Then you will receive json response with Like Count:-

{
 "id": "12345",
 "link": "http://www.facebook.com/pages/MY iOS Page/102445859460201",
 "likes": 150,
 "type": "page"
 }

Code:-

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 

  }
Vizllx
  • 9,135
  • 1
  • 41
  • 79
  • I give you a reference http://www.espncricinfo.com/bangladesh-v-pakistan-2015/content/player/41434.html Here we can see number of likes on player without any login, is it possible with iOS-SDK ? – Haris May 13 '15 at 05:22
  • Have to dig more for that, but in case of iOS i don't think it is certainly possible. – Vizllx May 13 '15 at 05:27
  • Thank you, I am also looking for confirmation somewhere – Haris May 13 '15 at 05:30
  • With this code FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"https://graph.facebook.com/{myobject-id}/" parameters:nil HTTPMethod:@"GET"]; I am still getting message "An access token is required to request this resource" – Haris May 13 '15 at 05:40
  • You cannot use FBSDKGraphRequest it will need user permission, you have send graph url request through NSURL and you will get the specified response. check my updated answer @Haris – Vizllx May 13 '15 at 05:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77680/discussion-between-haris-and-vizllx). – Haris May 13 '15 at 06:12
1

Got Response from Facebook Team :

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.

Haris
  • 1,822
  • 2
  • 22
  • 44
0

I got the solution from

How to get Likes Count when searching Facebook Graph API with search=xxx

Here in this link it's not the exact solution but i have tried my way and unfortunately it worked for me, and i am quite satisfied with it, still using it in my application.

 https://graph.facebook.com/v2.1/{Object-id}?fields=likes.summary(true)
Community
  • 1
  • 1
Chiragkumar Thakar
  • 3,616
  • 5
  • 37
  • 49
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mayank Jain May 13 '15 at 09:47
  • I have modified my answer Mr.@MayankJain please take a look on it. – Chiragkumar Thakar May 13 '15 at 10:26
0

You will need an access token, no need to login any user, you can generate an APP Access token to get that info .

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
   });

Thats more complicated but solves the necessity to login the user to get public informations from the graph .

David Augustus
  • 420
  • 3
  • 9