Sunday, August 4, 2013

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"https://graph.facebook.com/"]];
    
    NSString *link = [NSString stringWithFormat:@"https://graph.facebook.com/%@/likes/%@", USER_ID, PAGE_ID];
    
    NSDictionary *params = @{@"access_token" : [[[FBSession activeSession] accessTokenData] accessToken]};
    
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
                                                            path:link
                                                      parameters:params];
    
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON ) {
        
        if([[JSON objectForKey:@"data"] count] == 0){
            
            // The page is not liked.
        }
        else{
            
            // The user likes the page.
        }
    }
    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
        
                                             
    }];

    [operation start];
That's it, don't hesitate to comment, to share your knowledge and to correct me.

1 comment: