ValentiGoClimb
ValentiGoClimb

Reputation: 750

iOS Facebook Api, make a like to a comment post

I want to like a comment of a post on Facebook, I use the same as like the post. For like a post, it works, but for like a comment fail.

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

My Code:

[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@/likes", postId_]
                             parameters:nil
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
                        {  //Error:
                        }];

The Error is:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x158999b0 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdk:ParsedJSONResponseKey={ body = { error = { code = 100; message = "(#100) Error finding the requested story"; type = OAuthException; }; }; code = 400; }, com.facebook.sdk:ErrorSessionKey=}

Upvotes: 2

Views: 890

Answers (3)

Sergei Nikitin
Sergei Nikitin

Reputation: 788

I think, we all can trust Facebook, yes? :)

Go to https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes, select "IOS SDK" tab and look at the code.

Upvotes: 0

Basheer_CAD
Basheer_CAD

Reputation: 4919

Here is how I do it, and it works like a charm

    // post is my module object, encapsulates the info form the post
    // pass the post ID
    NSString *graphPath = [NSString stringWithFormat:@"%@/likes", post.postID];

    FBRequest *request = [FBRequest requestForGraphPath:graphPath];
    // DELETE or POST the like
    NSString *method = post.liked?@"DELETE":@"POST";
    [request setHTTPMethod:method];

    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        BOOL success = YES;
        success = (error)?NO:YES;
        if(success) {

        }
    }];

Note: make sure you have publish permissions

Upvotes: 1

Sergei Nikitin
Sergei Nikitin

Reputation: 788

In my project I use the following code:

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:URL, @"object", nil];

  if (FBSession.activeSession.isOpen) {
    if (FBSession.activeSession.accessTokenData.accessToken) {
      [FBRequestConnection startWithGraphPath:@"/me/og.likes"
                                   parameters:params
                                   HTTPMethod:@"POST"
                            completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              NSLog(@"Just liked on Facebook!");
                            }];
    } else NSLog(@"Cannot open FBSession");
  }

There no code for opening or initializing FBSession - I hope, it's not a problem?

Upvotes: 0

Related Questions