3

I want to check if the user has liked my page or not. Here, I initialise the request for a list of likes the user has...

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
{
    [self.facebook setAccessToken:[defaults objectForKey:@"FBAccessTokenKey"]];
    [self.facebook setExpirationDate:[defaults objectForKey:@"FBExpirationDateKey"]];
}

if (![self.facebook isSessionValid])
{
    [self.facebook authorize:[[NSArray alloc] initWithObjects:@"publish_stream, user_likes", nil]];
}
else
{
[self.facebook requestWithGraphPath:@"me/likes" andParams:nil andHttpMethod:@"POST" andDelegate:self];    
}

The code executes to requestWithGraphPath. However it never works, I get "The operation couldn’t be completed. (facebookErrDomain error 10000.)".

ABCD
  • 7,914
  • 9
  • 54
  • 90

1 Answers1

6

You need a get request to for likes not a POST so your problem I think is here:

[self.facebook requestWithGraphPath:@"me/likes" andParams:nil andHttpMethod:@"POST" andDelegate:self];

this needs to be:

[self.facebook requestWithGraphPath:@"me/likes" andParams:nil andHttpMethod:@"GET" andDelegate:self];

This will give you the full list of likes. If you want to find a single like, however, it looks like you'll have to do an FQL query to:

https://api.facebook.com/method/fql.query?query=SELECT+user_id%2Cobject_id%2C+post_id+FROM+like+WHERE+user_id%3Dme%28%29%20and%20object_id=<OBJECT_ID_TO_CHECK>&access_token=<YOUR_ACCESS_TOKEN>

Execute this through the iOS SDK like this mentions: https://stackoverflow.com/a/6372236 and if you get anything back the user has liked it. Let me know if this helps. Thanks!

Edit: You actually can do a single query with the graph api. It's like this:

https://graph.facebook.com/me/likes/<OBJECT_ID>

So just plop your object id into the request:

[self.facebook requestWithGraphPath:@"me/likes/<OBJECT_ID>" andParams:nil andHttpMethod:@"GET" andDelegate:self];

and you should be good.

Community
  • 1
  • 1
user1434226
  • 76
  • 1
  • 4