Search code examples
iosobjective-cfacebook-opengraphfacebook-ios-sdk

How to get callbacks for Facebook iOS SDK Like action?


Trying to perform the built-in-like using the Facebook iOS SDK. I've found snippets like the one below but how can I get notified of the requests status? I have no way of knowing whether the request actually caused a Like, failed, and for what reasons.

Q: How to get callbacks from FBRequest?

// Trying to perform built-in-like
[FBRequest requestWithGraphPath:@"me/namespace:like"        
                     parameters:@{@"recipe":@"http://myurl.com"} 
                     HTTPMethod:@"POST"];

Solution

  • According to the FBRequest API the requestWithGraphPath method does not make an actual call.

    //Returns a newly initialized request object that can be used to make a
    //Graph API call for the active session.
    requestWithGraphPath:parameters:HTTPMethod:
    

    The call itself can be made with startWithCompletionHandler:.

    - (FBRequestConnection*)startWithCompletionHandler:(FBRequestHandler)handler;
    

    Looking at the API for FBRequestConnection, FBRequestHandler is a block that is passed to register for a callback with the results of that request once the connection completes. In other words, it will be called when the request completes with a success, error, or cancel action.