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.
Showing posts with label AFNetworking. Show all posts
Showing posts with label AFNetworking. Show all posts
Sunday, August 4, 2013
Friday, April 5, 2013
Implement a (Like) action for any object on Facebook (except the pages) using AFNetworking.
Posted by Polaris on 7:41 PM
NSURL *baseURL = [NSURL URLWithString:@"https://graph.facebook.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
NSString *link = [NSString stringWithFormat:@"/%@/likes", @"OBJECT_ID"];
NSDictionary *params = @{@"access_token" : [[[FBSession activeSession] accessTokenData] accessToken]};
[httpClient postPath:link parameters:params success:^(AFHTTPRequestOperation *op, id result) {
NSLog(@"result %@", result);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error %@", error);
}];
That's it, don't hesitate to comment, to share your knowledge and to correct me.Posted in AFNetworking, iOS
Subscribe to:
Posts (Atom)
Check if a Facebook page is liked using AFNetworking.