FQL and using its result - facebook

how can we use the result that we get from FQL
specifically
how can we use the result to save it in another array
take in consideration that for iOS

an example:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"SELECT uid,name FROM user WHERE uid=4", #"query",
nil];
[facebook requestWithMethodName: #"fql.query"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];

Related

How to make a friend request with facebook ios sdk?

i'm using the facebook iOS sdk.
I need to send friend requests between users of facebook, from an iOS app.
I know that can not be sent via graph API. I'm trying to through dialog of facebook i do not know how.
Can anyone help me?
This is my code:
Facebook *face = [[Facebook alloc] initWithAppId:#"APP_ID" andDelegate:self];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"user_id", #"id",
nil];
[face dialog:#"me/friends"
andParams:params
andDelegate:self];
With this code i get a dialog with this text: "The page you requested was not found"
Ok I found a solution.
I have created a NSMutableDictionary to make a "appRequest" with their corresponding parameters but finally indicated that the type of dialogue is a "friends".
It's a strange solution but it works.
Facebook *face = [[Facebook alloc] initWithAppId:FBSession.activeSession.appID andDelegate:nil];
face.accessToken = FBSession.activeSession.accessToken;
face.expirationDate = FBSession.activeSession.expirationDate;
if ([face isSessionValid]){
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"My Title", #"title",
#"Come check out my app.", #"message",
userId, #"id",
nil];
[face dialog:#"friends"
andParams:[params mutableCopy]
andDelegate:nil];
}
This may help you
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys: message, #"message", title, #"title", nil];
[[self facebook] dialog: #"apprequests"
andParams: [params mutableCopy]
andDelegate: delegate];
See this question for further details and also this document.

Facebook Graph API friends birthdays

I searched a lot, I didn't succeeded in getting the friends birthday
[facebook requestWithGraphPath:#"me" andDelegate:self];
what should I write instead of me to get the friends birthdays.
thanks
Try with below:
[facebook requestWithGraphPath:#"me/friends"
andParams:[ NSDictionary dictionaryWithObjectsAndKeys:#"picture,id,name,link,gender,last_name,first_name",#"fields",nil]
andDelegate:self];
Let me know in case of query/difficulty.
Sometimes,
Birthday value will be like "null" or only "month & date" or the "full date". So you have to check it manually.
I have one requirement in which I have to display only Month & Date.
You can check it from below function:
+(NSString *)getShortDate:(NSString *)pstrDate{
NSArray *arrayDateData = [pstrDate componentsSeparatedByString:#"/"];
NSString *strShortDate = #"";
if([arrayDateData count]>=2){
strShortDate = [NSString stringWithFormat:#"%#/%#", [arrayDateData objectAtIndex:0], [arrayDateData objectAtIndex:1]];
}
return strShortDate;
}
Here, "pstrDate" date value is Facebook birthday date value.
I hope it will be helpful to you.
Cheers.
I found an answer & it is as follows:
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"select uid,name,birthday_date from user where uid in (select uid2 from friend where uid1=me())", #"query",
nil];
[[StaticFacebook getFacebook] requestWithMethodName: #"fql.query"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
Get friends_birthday using graph api:
[facebook requestWithGraphPath:#"me/friends?fields=id,name,gender,picture,birthday" andDelegate:self];
and add permissions like this:
_permissions = [[NSArray arrayWithObjects:
#"read_friendlists",#"publish_stream ,user_checkins",
#"friends_checkins", #"publish_checkins",#"email", nil]
retain];

Facebook attachment data format for "media" key. (related to Posting Image+Text on friend's wall )

I am trying to post some data at one of the friend from my friend list .
I am able to post some text on my friend's wall.But it fails to post the image and other data . (Presentl I can only see the text for key "message" and rest of the part does not appear in the post.
SBJSON *jsonWriter = [[SBJSON new] autorelease];
/*
Action LInks
*/
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"Always Running",#"text",#"http://itsti.me/",#"href", nil], nil];
//Json Object Conversion
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
/*
Media Data in this case an image.
*/
**NSMutableDictionary *dictMedia=[NSMutableDictionary dictionaryWithObjectsAndKeys:#"image",#"type",#"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg",#"src",#"www.fizzysoftware.com",#"href", nil];
NSArray *mediaArray=[[NSArray alloc] initWithObjects:dictMedia, nil];
NSString *mediaJsonString=[jsonWriter stringWithObject:mediaArray]; // error:actionLinksStr]
//Attatchment Data :Include media data,action link etc.
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
#"First Title", #"name",
#"This is the subtitle", #"caption",
#"This is is description", #"description",
mediaJsonString, #"media", nil];
//Json conversion of the attachment data.
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];**
//Main parameter
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Share on Facebook", #"message",
actionLinksStr, #"action_links",
attachmentStr, #"attachment",
nil];
//Post to friend's wall, whose uid is friend_uid
[ _facebook requestWithGraphPath:[NSString stringWithFormat:#"friend_uid/feed/"] andParams:params
andHttpMethod:#"POST" andDelegate:self];
Any suggestions where I am mistaking in sending the attachment. I am able to only see the "message" part of the param in my post and none of the attachment data is shown in the post.
Thanks in advance.
You can try using the new approach to open a feed dialog and set the "to" (used to be target) parameter along with the rest of the attachments directly as params.
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
#"some facebook id", #"to",
#"http://yourpage.com", #"link",
#"http://yourpage.com/image.png", #"picture",
#"the name", #"name",
#"the caption", #"caption",
#"the description", #"description",
nil];
[_facebook dialog: #"feed" andParams: params andDelegate: self];
Here you have some documentation regarding the feed dialog.
http://developers.facebook.com/docs/reference/dialogs/feed/
If you are posting directly, you should be doing something like this:
[_facebook requestWithGraphPath:#"some facebook id/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
Doc regarding direct posts:
http://developers.facebook.com/docs/reference/api/user/#posts
Hope this helps.

Tagging Photos via Facebook GraphAPI

Facebook recently added photo-tagging capabilities to its Graph API:
http://developers.facebook.com/blog/post/509/
I am using FbConnect on iPhone to upload a picture and tag my page inside it.
So, my first call is:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.imageToPost, #"picture",
#"My caption!", #"name", #"tags",
nil];
[self.theFacebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
This correctly returns:
{
id = 2092859844825;
}
Then I make another call:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
FACEBOOK_PAGE_ID,#"to",
#"160",#"x",
#"240",#"y",
nil];
[self.theFacebook requestWithGraphPath:[NSString stringWithFormat:#"%#/tags",photoId]
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
Then I get:
{contents = "OAuthException"}
{contents = "(#121) Invalid photo id"}
But what ID does it expect from me?
Submitting the same request in GET method, it doesn't give the error, so I think the id is correct. Any ideas??
What permissions do you have set? Check you have the user_photos permission

How do I retrieve a friend list from Facebook and show it in a table view?

How do I retrieve a friend list from Facebook and show it in a table view in iOS?
Hii,
Write a FQL to extract User friend List,
NSString *query = #"SELECT uid, name, pic_square, status FROM user WHERE uid IN (";
query = [query stringByAppendingFormat:#"SELECT uid2 FROM friend WHERE uid1 = %#)",self.uid];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
query, #"query",
nil];
[_facebook requestWithMethodName: #"fql.query"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
Hope this Helps!!!