How to Query Facebook uid's for User Friends' Likes - objective-c

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!

Related

Facebook Open Graph startForPostWithGraphPath returning "FACEBOOK_NON_JSON_RESULT" = true

I'm trying to configure an Open Graph post. I've followed the code examples on the FB developer site, and, using a test_user, a post is supposedly successfully generated. Here is my code:
- (void)createOGObjectForImage:(NSURL *)imageURL
{
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"ogminigame:mini_game"
title:#"Mini Game"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:imageURL
description:#""];
[FBRequestConnection startForPostWithGraphPath:#"me"
graphObject:object
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Result: %#", [result description]);
[self createOGActionWithResult:result];
} else {
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
[self sharePhotoWithShareDialog:self openGraphAction:nil];
}
}];
}
However, nothing is appearing on the test user wall. When I step through the code, I can see that when I create the OG object, the result has the following contents:
"FACEBOOK_NON_JSON_RESULT" = true;
More specifically, it looks like this:
So when I create my Action, when I try to retrieve the objectID using:
NSString *objectId = [result objectForKey:#"id"];
it obviously returns nil. Am I missing a stage with the result object? I've tried searching for similar problems but there doesn't seem to be much in the way of an explanation.
Well, it seems the code supplied on the Facebook developer site where you supply your custom stories is incorrect. Namely, it should look like:
- (void)createOGObjectForImage:(NSURL *)imageURL
{
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:#"ogminigame:mini_game"
title:#"Mini Game"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:imageURL
description:#""];
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(#"Result: %#", [result description]);
[self createOGActionWithResult:result];
} else {
NSLog(#"Error posting the Open Graph object to the Object API: %#", error);
[self sharePhotoWithShareDialog:self openGraphAction:nil];
}
}];
}
So you cast the dictionary to an FBOpenGraphObject, rather than an FBGraphObject and call startForPostOpenGraphObject instead of startForPostWithGraphPath.
It seems to me Facebook need to be a bit more consistent with their documentation.
I still have nothing showing on the test_account page, but at least the above doesn't seem to be the cause of the issue...

parse.com API - how to run a query inside parse classes files?

I will try to explain myself as best as I can.
My app has a login & sign Up using the Parse API .
after signing or logging the User see a page with a Button and a Text Field which he can write Numbers in it ,
let's say he write , for example: 1234.
the button job is to save the data from the text field
Now i'm sure my Button method isn't the best way, but it's work :-)
NSString *whoIsTheUser = [PFUser currentUser];
NSString *phoneNumbers = phoneNumberField.text ;
NSString *fullData = [NSString stringWithFormat:#" %# , %#", whoIsTheUser, phoneNumbers];
NSLog(#" %#, %# ", whoIsTheUser, phoneNumbers);
PFObject *addValues= [PFObject objectWithClassName:#"phoneNumber"];
[addValues setObject: fullData forKey:#"numbers"];
[addValues saveInBackground];
So now what i'm having is the data saved to parse site under class of Numbers (forKey:#"numbers")
and it's look like this :
<PFUser:hqExhaYaIN:(null)> {email = "buffo#yahoo.com";username = buffo;} , 1234
what I'm trying to do is to add another button which going to check if theres another user
who wrote the same numbers and then send an alert or do something .
I have tried to read about the PFQuery but didn't find any solution.
is it even possible to run Query in the classes name ? or maybe theres another way to do it ( within the parse site ) ?
thank you so much for any suggestion !
It looks like you need to split up fullData in your parse objects and do something like this
PFQuery* numQuery = [PFQuery queryWithClassName:#"phoneNumber"];
[numQuery whereKey:#"numbers" equalTo:phoneNumbers];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
if(!error)
{
for(PFObject *numObject in objects)
{
//Do what you need to do here
}
}
else
{
//handle error
}
}
EDIT - this means you would save your PFObjects like this
PFObject *addValues= [PFObject objectWithClassName:#"phoneNumber"];
[addValues setObject: phoneNumbers forKey:#"numbers"];
[addValues setObject: whoIsTheUser forKey:#"theUser"];
[addValues saveInBackground];
i hope it's going to help someone like it's helps me , if you want to query for info without the user info use those lines
PFQuery* numQuery = [PFQuery queryWithClassName:#"phoneNumber"];
[numQuery whereKey:#"numbers" equalTo:phoneNumbers];
[numQuery whereKey:#"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
all I had to do is add notEqualTo and CurrentUser :-)

How to get user_likes from Facebook SDK

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

Get a users timeline from the Facebook API

I'm currently using this piece of code to get a users feed from Facebook:
FBRequest *friendsRequest = [FBRequest requestWithGraphPath:[NSString stringWithFormat:#"%#?fields=cover,first_name,last_name,relationship_status,feed", self.friendID] parameters:[[NSMutableDictionary alloc] initWithObjectsAndKeys:#"en_EN", #"locale", nil] HTTPMethod:nil];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary* result,
NSError *error) {
postsArray = [[NSMutableArray alloc] initWithArray:[result valueForKeyPath:#"feed.data"]];
[tableView reloadData];
NSLog(#"Data found: %#", [result description]);
NSLog(#"Posts: %i", postsArray.count);
}];
However, this 'feed' also includes things like 'XXX on his own post' or 'User A liked Post B' and I'd like to get just what the user has posted and what others have posted onto his wall (like if you go to a user timeline on facebook.com or in the iOS apps). Is that possible? If not, how can I found out if a status is a 'like' or 'commented on...'?
Why not use the read_stream permission and FQL
Documentation here
You can loop through results and find where type is equal to:
46 - Status update
56 - Post on wall from another user

Filter the friend returned by FBFriendPickerViewController in new Facebook 3.0

I have an Facebook app on http://developer.facebook.com of type "Native iOS" which is connected to the actual iOS app using the new Facebook iOS SDK 3.0.
How can I know if the multiple people that already install the the app and authorize the Facebook app too so I can put them in some list, but this not my question because I know that there is a field called "installed" that return true when the user install the app.
So if I want to filter the returned friend by the FBFriendPickerViewController based on if the user use the app, so how I can use the installed field or something else to filter the friends.
Note: I know where to filter the friend (*) all I need is the field or the property that I need to check to make sure the user is install my app.
*- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker
shouldIncludeUser:(id<FBGraphUser>)user
I found a way to do this :
I create a method that send an FQL to those I need (for example my friends that they are male)
and then compare those returned by this request with the already exists by the FBFriendPickerViewController using the method :
- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker shouldIncludeUser:(id<FBGraphUser>)user
for the request :
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:#"query", #"q", nil];
[FBRequestConnection startWithGraphPath:#"/fql" parameters:queryParam HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops" message:#"Some thing go wrong !, Try again" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
{
NSArray *friendInfo = (NSArray *) [result objectForKey:#"data"];
for(int i = 0; i < [friendInfo count]; i++)
{
[self.friendsNames addObject:[[friendInfo objectAtIndex:i] objectForKey:#"name"]];
}
}
}];
As you see I have an NSArray that store the filtered friend, the next step is to compare them in the delegate method above.
Hope you find it useful.