How to get user_likes from Facebook SDK - objective-c

Im trying to get the user's likes from Facebook, I've been looking for a while for an example and I didn't find it.
With the code I have I get the user's profile information, but no likes. I was wondering if I was doing something wrong and then I looked at Facebook Developers and I found this https://developers.facebook.com/docs/ios/user-data-ios-sdk/
If you take a look at the JSON that is returned you won't see any likes, so what does that mean? There's no way to fech the likes of a user? Why even bother calling the permission "user_likes"?
Any direction will be very appreciated.
Thanks.

Well, let's put it this way. Facebook documentation is confusing.
To get he user likes you have to use FQL, the snippet, would be something like this.
// Query to fetch the active user's friends, limit to 25.
NSString *query =
#"SELECT page_id, type FROM page_fan WHERE uid = me()";
// Set up the query parameter
NSDictionary *queryParam = #{ #"q": query };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
}];
This way you are getting the users Pages id. If you need something else, take a look at the documentation here: https://developers.facebook.com/docs/reference/fql/page_fan

Related

LinkedIn Objective C sharing

we are working on sharing with the linkedIn objective C SDK, latest version.
Using this code:
NSString *url = #"https://api.linkedin.com/v1/people/~/shares";
NSString *payload = #"{\"visibility\":[{\"code\":\"anyone\"}],\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\"}";
if ([LISDKSessionManager hasValidSession]) {
[[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload success:^(LISDKAPIResponse *response) {
// do something with response
NSLog(#"Success: %#", response.description);
dispatch_async(dispatch_get_main_queue(), ^{
_responseLabel.text = response.description;
});
} error:^(LISDKAPIError *apiError) {
// do something with error
NSLog(#"Error: %#", apiError.description);
dispatch_async(dispatch_get_main_queue(), ^{
_responseLabel.text = apiError.description;
});
}];
}
lifted pretty much from their sample page. (Had to update a bit, the URL on the site was declared with initWithString which is no longer around).
We have requested and receive a valid session and requested the w_share permission as required in the updated spec.
Here is the actual error:
Error Domain=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=<LISDKAPIResponse: 0x1288cc100>}
Any hints would be appreciated!
According to Linked-in's docs and API Console, XML is the default and you need to specify that you want JSON, like this:
https://api.linkedin.com/v1/people/~/shares?format=json
And possibly with a header (not sure if the LISDKAPIHelper) knows how to do that part.
The documentation is really unclear. I suggest you capture the packets with something like CharlesProxy and see if what is getting sent is what you expect. Alternatively, use your same code, but send XML instead of JSON.

facebook Graph api 2.2 issue

How can i get the list of all friends using the graph api 2.2 and also i want to post the text on the friends wall. in iOS application
I tried:
[FBRequestConnection startWithGraphPath:#"/me/friends"
parameters:nil
HTTPMethod:#"GET"
completionHandler:^(
FBRequestConnection *connection,
id<FBGraphUser> result,
NSError *error
) {
/* handle the result */
dicResult =(NSDictionary *) result;
NSLog(#"%#", dicResult);
[self.tblFriendListGroup reloadData];
}];
You can´t get ALL friends anymore, only those who authorized your App too.
You can´t post on the wall of friends. That possibility was removed many years ago because it would always be spam.
Check out the changelog: https://developers.facebook.com/docs/apps/changelog?locale=en_GB

Check if Authenticated User Likes A Certain Page (Using SLRequest)?

I've been looking through the open grpah reference docs, and can't seem to find a good example related to SLRequest regarding users and whether they like a certain page or not. I don't want to iterate through their entire list of likes.
I was looking at https://developers.facebook.com/docs/graph-api/reference/user/likes/ but I'm not sure how to work with it and SLRequest, I've done the following but I'm receiving the following response:
Received Response: {"error":{"message":"An active access token must be used to query
information about the current
user.","type":"OAuthException","code":2500}}
Thing is all of this code only runs if the suer has previously authenticated and granted permission, and so it must have found an account, yet I still get this respond. Could it be that I'm not requesting a specific permission? I've requested, "email, public_actions, user_likes and public_stream".
BTW I do have another view controller where I ask for these permissions (except user_likes), and everything works in that one. Is there anything that I'm missing here? Thanks!
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/likes/{MYPAGEID}"];
[SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:nil];
[updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData ) {
NSLog(#"Received Response: %#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSLog(#"Successful Connection");
} else {
}
} else {
NSLog(#"No response.");
}
}];
The error that you are getting is received when you try to make calls like /me but no user is currently logged-in to your app or the user has already logged-out of the app.
I'm not sure of your complete flow of the app but you can try this to validate your access token and call- you have the access token right? so, with your current API call just add an extra parameter access_token with its value.

How to show friends list from Facebook like Tinder dose on the Profile section?

I would like to know how to show friends from Facebook like on the app "Tinder" (on the profile section of Tinder), which is basically one horizontal cell that shows all your Facebook friends.
I know how to fetch user's friends from Facebook using the FacebookSDK and i know how to make the profile picture rounded, which it's only this line of code- self.ProfilePictureView.layar.cornerRadius = ....
I just don't know how to implement that cell to present the friends list.
Please, if anyone can help...
Thanks anyway!
for this condition, you need to implement your own facebook picker.
here is snippet from one of my project.
it return the list of your friend. you can show it in your table view & customize the tableview cell with round corner.
check this
- (void)getFriends:(void(^)(NSArray *friends, NSError *error))completionBlock
{
FBRequest* friendsRequest = [FBRequest requestForMyFriends];
friendsRequest.session = [FBSession activeSession];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary* result, NSError *error) {
if(error) {
completionBlock(nil, error);
return;
}
NSArray* friends = result[#"data"];
completionBlock(friends, nil);
}];
}

How to Query Facebook uid's for User Friends' Likes

I have created an application in Xcode 4.5. It incorporates a Facebook login process, a query of my friends and their basic info and some newsfeed publishing processes successfully. However, I am having an issue in trying to query which of my friends have "liked" a certain Facebook object, in this case, a photo. Here is what I have done thus far:
Requested the following permissions in the - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI method:user_about_me, read_friendlists, friends_likes, read_stream,
friends_likes, user_likes, friends_photos,user_photos.
I went on Facebook and found a photo that has been liked by some of my Facebook friends. I then investigated the id of the photo by going to https://graph.facebook.com/?ids=https://www.urlToFBPhoto
I used the following query code (as per the facebook developer page regarding such queries: url) SELECT user_id FROM like WHERE object_id="10152365284110475".
I was expecting that when I did an NSLog of the resulting data from this query, I would get uids of the few friends who I know like the photo. But instead, the query returned no results whatsoever.
For clarity, here is the full query code I used:
- (IBAction)getFriendLikes:(id)sender
NSString *objectID = #"10152365284110475"; //object id of a friend's FB photo
NSString *query = [NSString stringWithFormat:
#"{"
#"'friendlikes':'SELECT user_id FROM like WHERE object_id=%#'," //no data
//#"'friends':'SELECT uid2 FROM friend WHERE uid1 = me()'," //returns data
//#"'friendinfo':'SELECT uid, name, sex, pic_big, pic_square FROM user WHERE uid IN
//(SELECT uid2 FROM #friends)'," //returns data
#"}",objectID];
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:
query, #"q", nil];
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"Result: %#", result);
}
NSArray *friendInfo = (NSArray *) [[[result
objectForKey:#"data"]
objectAtIndex:1]
objectForKey:#"fql_result_set"];
[DataController dc].fbArray = nil;
[DataController dc].fbArray = friendInfo;
//post callback tasks
} ];
}
If anyone can offer any assistance I would greatly appreciate it!