How to make a friend request with facebook ios sdk? - iphone

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.

Related

posting on facebook newsfeed is not working

i am running hackbook sample for iphone using facebook sdk but when i try to publish on my newsfeed it is posting on my timeline but it is not showing in my newsfeed . i tried another example from this facebook example link but it is also posting on my timeline but not in my newsfeed.the code for publishing using hackbook sample is
- (void)apiDialogFeedUser
{
currentAPICall = kDialogFeedUser;
SBJSON *jsonWriter = [[SBJSON new] autorelease];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"Get Started",#"name",#"http://m.facebook.com/apps/hackbookios/",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
// Dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"I'm using the Hackbook for iOS app", #"name",
#"Hackbook for iOS.", #"caption",
#"Check out Hackbook for iOS to learn how you can make your iOS apps social using Facebook Platform.", #"description",
#"http://m.facebook.com/apps/hackbookios/", #"link",
#"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", #"picture",
actionLinksStr, #"actions",
nil];
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] dialog:#"feed" andParams:params andDelegate:self];
}
anybody else has face this type of issue
any suggestions will be great help
Try using the OFFICIAl iOS dev tutorial made by Facebook themselves:
iOS Tutorial

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 to include a link in my feed-post using FBConnect from iPhone app?

I've got some code that does a bunch of set-up, then posts to Facebook using FB-connect. At one point, I have something like this:
NSString *description =
#"Wow, what a great app! "
#"Download it free: "
#"<a href=\"http://itunes.apple.com/us/app/myApp/id12345?mt=8\">"
#"On iTunes AppStore."
#"</a>"
;
// post FB dialog
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// #"This is what I say about myApp:", #"message", // user msg
#"MyApp!", #"name", // Bold/blue name
#"MyApp is cool!", #"caption", // 1st line
description, #"description", // 2nd line
#"http://itunes.apple.com/us/app/myApp/id12345?mt=8", #"link",
#"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", #"picture",
nil];
[facebook dialog: #"feed"
andParams: params
andDelegate: self];
And it ALMOST works! The only problem is: in my description string, everything between "<a href..." and "</a>" doesn't display on my facebook wall.
So the question is: how do I add a link (anchor-tag style) as part of my post?
It is not possible to add links in the description, however you can achieve the same result using the "properties" and "actions" keys, as documented here:
Facebook API Feed Dialog Documentation
The code would be as follows:
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary *propertyvalue = [NSDictionary dictionaryWithObjectsAndKeys:#"On iTunes AppStore", #"text", #"http://itunes.apple.com/us/app/myApp/id12345?mt=8", #"href", nil];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:propertyvalue, #"Download it free:", nil];
NSDictionary *actions = [NSDictionary dictionaryWithObjectsAndKeys:#"Download it free", #"name",#"http://itunes.apple.com/us/app/myApp/id12345?mt=8", #"link", nil];
NSString *finalproperties = [jsonWriter stringWithObject:properties];
NSString *finalactions = [jsonWriter stringWithObject:actions];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
userfbid, #"to",
#"http://itunes.apple.com/us/app/myApp/id12345?mt=8", #"link",
#"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", #"picture",
#"Name name name", #"name",
#"Caption caption caption", #"caption",
#"Description description description", #"description",
finalproperties, #"properties",
finalactions, #"actions",
nil];
[_facebook dialog:#"feed" andParams:params andDelegate:self];
The properties will appear in the stream attachment beneath the description, with each property on its own line.
The actions will appear next to the "Comment" and "Like" link under posts.
In the attached screenshots you will see how both properties and actions look like.
The first screenshot shows how it looks when the dialog pops up on the iPhone.
The second screenshot shows the Facebook post with the properties object.
The third screenshot shows the Facebook post with both the properties and actions objects.
Hope this helps.
#lancelotavery gave the correct answer, and I accepted it. I had just moments before discovered the properties field and was coming back to enter this answer when I saw his.
I am entering this answer only to demonstrate that the desired behaviour can be done without adding a jsonwriter.
As expected, this was one of those things that's super-easy, once you know the trick.
The answer is: you can't put HTML in your description field.
HOWEVER, the facebook dialog accepts a parameter called "properties", which can be either a string or a string-representation of another dictionary, which can have exactly 2 values, TEXT and HREF. So, adding a line like this one:
NSString* propString = #"{\"Download it free: \":{\"href\":\"http://bit.ly/12345\",\"text\":\"On iTunes AppStore\"}}";
and then inserting this pair into params:
propString, #"properties",
made everything work. So the final edit of my code from above looks something like this:
NSString *description =
#"Wow, what a great app! "
#"Download it free: "
#"<a href=\"http://itunes.apple.com/us/app/myApp/id12345?mt=8\">"
#"On iTunes AppStore."
#"</a>"
;
NSString* propString = #"{\"Download it free: \":{\"href\":\"http://bit.ly/12345\",\"text\":\"On iTunes AppStore\"}}";
// post FB dialog
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// #"This is what I say about myApp:", #"message", // user msg
#"MyApp!", #"name", // Bold/blue name
#"MyApp is cool!", #"caption", // 1st line
description, #"description", // 2nd line
#"http://itunes.apple.com/us/app/myApp/id12345?mt=8", #"link",
#"http://farm6.static.flickr.com/5230/5576336654_075c2abcf9_s.jpg", #"picture",
propString, #"properties",
nil];
[facebook dialog: #"feed"
andParams: params
andDelegate: self];

iphone : FBConnect Auto post to user wall

i want to auto post to a user wall from my iphone applications ( without that "publish" "skip" dialog box ). how i can do that ?
the following should be called in the class that implements FBSessionDelegate and FBRequestDelegate:
Facebook *_facebook = [[Facebook alloc] initWithAppId:kAppId];
NSArray *_permissions = [[NSArray arrayWithObjects:
#"read_stream", #"offline_access",nil] retain];
[_facebook authorize:_permissions delegate:self];
And that is the call for fb post (should be used in the same class):
NSString *message = #"This is the message I want to post";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message",
nil];
[_facebook requestWithMethodName:#"stream.publish"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
If you want to post a message on the wall of other user you should include "uid" parameter in your params dictionary. Please consult http://developers.facebook.com/docs/reference/rest/stream.publish/
P.S. There are all the necessary examples in the iPhone Facebook connect SDK sample code, so please do not afraid to investigate just a little bit ;)