I am looking for some documentation or sample code on how to send multiquery fql requests to Facebook via iOS SDK.
I found some older samples but they doesnt work for me.
I have populated an NSDictionary with the queries and I try to send the request via
[[FBRequest requestWithDelegate:self] call:#"facebook.fql.multiquery" params:params];, as stated in the samples I have read, but I get an "unrecognized selector sent to class" error and I cant find the "requestWithDelegate" method in FBRequest.h either. Is it deprecated?
Some help on this would be very appreciated!
// Construct your FQL Query
NSString* fql = [NSString stringWithFormat:#"SELECT uid, name, hometown_location from user where uid IN (SELECT uid2 FROM friend WHERE uid1=%lld) and hometown_location != '' ORDER BY rand() limit 4", facebookId];
// Create a params dictionary
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObject:fql forKey:#"query"];
// Make the request
[facebook requestWithMethodName:#"fql.query" andParams:params andHttpMethod:#"GET" andDelegate:self];
The the delegate FBRequestDelegate will be call with the response. Depending on your needs, you'll do something like:
- (void)request:(FBRequest*)request didLoad:(id)result {
NSLog(#"didLoad() received result: %#", result);
}
The facebook object is created like:
Facebook * facebook = [[Facebook alloc] initWithAppId:kAppID];
More info on how to set this up can be found here:
https://developers.facebook.com/docs/guides/mobile/
And depending on your FQL query, you will need permissions from the user. See the list of permissions here:
https://developers.facebook.com/docs/authentication/permissions/
There is also a test console for FQL queries here:
https://developers.facebook.com/docs/reference/rest/fql.query/
And if you want to do an Multiquery instead of a single query, it would look like:
NSString* fql1 = [NSString stringWithFormat:
#"select uid2 from friend where uid1 == %lld order by rand() limit 10", facebookId];
NSString* fql2 = [NSString stringWithFormat:
#"select uid, name from user where uid in (select uid2 from #queryID)"];
NSString* fql3 = [NSString stringWithFormat:
#"select uid, status_id, message from status where uid in (select uid from #queryName) limit 1"];
NSString* fql = [NSString stringWithFormat:
#"{\"queryID\":\"%#\",\"queryName\":\"%#\",\"queryStatus\":\"%#\"}",fql1,fql2,fql3];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"queries"];
[facebook call:#"fql.multiquery" params:params];
Related
I am trying to get the list of all online friends using Graph API.
I am using the following..
[facebook requestWithGraphPath:#"me/friends?fields=id,name,online_presence" andDelegate:self];
but this gives me 0 results.
Thanks.
EDIT:
I already have the permissions for doing this from FB.
If you have the friends_online_presence permission correctly configured, try this:
NSString* method = #"fql.query";
NSString* fql = #"SELECT uid, online_presence FROM user WHERE uid IN (SELECT uid2 FROM friend where uid1 = me())";
NSDictionary* params = [NSDictionary dictionaryWithObject: fql forKey: #"query"];
[[self facebook] requestWithMethodName: method
andParams: [params mutableCopy]
andHttpMethod: #"GET"
andDelegate: delegate];
This will return you a list of friends with online presence: active, idle, offline or error.
I am creating a iPhone app in which i have to show friend list with their images.
I am using Facebook graph api. i am getting the friends id and name but not the images.
So please suggest me how i can get this?
Write a FQL to get list of facebook friends & their Pics
NSString *query = #"SELECT uid,name,first_name,last_name,pic_square FROM user WHERE uid IN (";
query = [query stringByAppendingFormat:#"SELECT uid2 FROM friend WHERE uid1 = %#)",userid];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"query",
nil];
[_facebook requestWithMethodName: #"fql.query"
andParams: params
andHttpMethod: #"POST"
andDelegate:self];
you will get a array in u r
-(void)request:(FBRequest *)request didLoad:(id)result
Sample
{
"first_name" =User;
"last_name" = R;
name = "User R";
"pic_square" = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/.jpg";
uid = 595sd1;
}
{},{} etc
Hope this helps!
Is there any way or code snippet from where I can get the idea of getting friends list of a facebook user for iPhone SDK from an iPhone application?
Thanks.
I hope this might be helpful to you
http://www.capturetheconversation.com/technology/iphone-facebook-oauth-2-0-and-the-graph-api-a-tutorial-part-2
Along with this you can also learn great things from
http://developers.facebook.com/docs/reference/api
https://github.com/reallylongaddress/iPhone-Facebook-Graph-API
This may helpful to you
//try this code
- (void) getFriendName :(id) sender {
self.modeString = #"friendName";
NSString * query = [NSString stringWithFormat:#"SELECT name FROM user WHERE uid IN (SELECT uid1 FROM friend WHERE uid2=me())",appDelegate.friendList];
NSLog(#"query :%#",query);
// NSString * query = [NSString stringWithFormat:#"SELECT uid, first_name, last_name, birthday_date, sex, pic_square, current_location, hometown_location FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 ORDER BY birthday_date",appDelegate.friendList];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"query",
nil];
[_facebook requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
I have 3 albums in my Face Book account.
profile
NaturePhoto
Profile Pictures
when i use below FQL Query the "request:didLoad:" delegate return the empty array.
NSString* fql =[NSString stringWithFormat:#"SELECT cover_pid,name FROM album WHERE owner == %lld", session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
[[FBRequest requestWithDelegate:self] call:#"facebook.fql.query" params:params];
I am really struck in Face book FQL.
It should be = not ==
A query for the current authenticated user would be
SELECT cover_pid,name FROM album WHERE owner = me()
Which returns a correct response
I want to retrieve the status data posted/published by friends of a user. I wrote the following code, but only get the user's own status updates. Could someone please help to tell me what's wrong with my code? Thanks!
NSString *fql = [NSString stringWithFormat:#"select uid,message from status where uid in (select uid2 from friend where uid1=%lld) order by time desc ", uid];
NSDictionary *params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
[[FBRequest requestWithDelegate:self] call:#"facebook.Status.get" params:params];
You need to change the call to use "facebook.fql.query" since you're doing a direct query.
Here's my code for getting the last 20 friends updates:
NSString* fql = [NSString stringWithFormat:
#"SELECT uid, pic_square, name, status FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld) AND status.time > 0 ORDER BY status.time DESC LIMIT 20", fbSession.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:#"query"];
last20FriendsStatusRequest = [FBRequest requestWithDelegate:self];
[last20FriendsStatusRequest call:#"facebook.fql.query" params:params];
Best regards,