How to send add friend request (to facebook user) from iOS application? - iphone

I know there are lot of questions on this topic but none of those have satisfactory answers. Again I am not so confident about help as 2 of my last 3 questions are unanswered. Well Still, ma question is, Is there any way we can send friend request to any facebook user from one iOS application? Of course we have user id of that user.
As I have googled much and went through many links including
how send friend request to a person in Facebook through iPhone app?
Can a facebook friend request be sent from my own app?
https://developers.facebook.com/docs/reference/dialogs/requests/
etc..
And finally I found it:
http://www.facebook.com/dialog/friends?id=100002487216939&app_id=123050457758183&redirect_uri=http://www.example.com/response/
This dialog do the same what I want. So is there any equivalent for this in graph. Or something in iOS sdk, FBDialogueDelegate. Any thing that can help me out.

For user-to-user requests, you can do this (using ARC):
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys: message, #"message", title, #"title", nil];
[[self facebook] dialog: #"apprequests"
andParams: [params mutableCopy]
andDelegate: delegate];
For app-to-user requests, you can do this:
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys: message, #"message", nil];
[[self facebook] requestWithGraphPath: #"[FRIEND ID]/apprequests"
andParams: [params mutableCopy]
andHttpMethod: #"POST"
andDelegate: delegate];
Make sure you have the right access tokens and the correct Facebook configuration (canvas page setup etc.) for each.

Related

Responding to Facebook Requests in iphone app

I’m using this to send a request to a friend on Facebook. I’d like for the person that received the request to be able to open it and receive a bonus for accepting the request. How would I go about acknowledging the request on the receiving end?
-(IBAction)sendRequest:(id)sender
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Come check out my app.", #"message",
nil];
AppDelegate *aDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[aDelegate.facebook dialog:#"apprequests" andParams:params andDelegate:self]
}
You should check the Android and iOS: Discovery via Requests Best Practices official blog post.
It discusses (among other things) how to send user requests along with some relevant data, and then how to identify the request and get the associated data.

How to post a UIImage to Facebook wall (iPhone/iPad)?

I have been looking around online at how to post a UIImage to the users Facebook wall using the Facebook SDK. However I'm really confused what the simplest option is. So far I have only used the Facebook SDK to create a connection and post a message to the wall like so:
// Create message
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Blah", #"name",
#"", #"caption",
#"", #"description",
#"http://www.xyz.com", #"link",
#"", #"picture", // THIS IS NOT BIG ENOUGH
nil];
// Post it to the users feed
[facebook dialog:#"feed" andParams:params andDelegate:nil];
This seems to work nicely and allows me to upload a short amount of text as well as an image. The issue I'm having is that the image is far too small. I need a way of allowing the user to upload a larger (in terms of viewing size) image as well as a short caption.
Please can someone offer a solution (ideally that could work off my existing code)?
I managed to achieve this thanks to #Malek_Jundi. Here is the code I used:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[facebook accessToken], #"access_token",nil];
[params setObject:#"Caption to go with image" forKey:#"name"];
[params setObject:myImage forKey:#"source"]; // myImage is the UIImage to upload
[facebook requestWithGraphPath:#"me/photos"
andParams: params
andHttpMethod: #"POST"
andDelegate:(id)self];

Post a photo to a page for iOS

I am trying to post a photo to a page that the user does not own. Note that all solutions that I found from other discussion threads require the user to be administrative and get the access_token of a page with *manage_pages* permissions.
However, what I want to do is different: Using iOS SDK to upload an image to a page, which has a setting that people can upload images to it.
I try several ways, but none of them works.
Here is how I get permissions
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"photo_upload",
#"share_item",
#"status_update",
#"manage_pages",
#"user_likes",
#"publish_stream",
nil];
[fb authorize: permissions];
Here are the codes for uploading the image
NSString *uri = [NSString stringWithFormat: #"%#/photos", FBPageId];
[fb requestWithGraphPath: uri
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
It kept posting the image to the user's album, which is not what I want.
I will really appreciate if anyone knows how to do it. Thank you!
I have two potential workarounds for you to try out:
Post the picture to the pages feed rather than to the {pageid}/photos.
Collect the albums for that page {pageid}/albums. Now with the correct album id, post the picture to {albumId}/photos.

how to post a photo and message to Facebook using the new Facebook GRAPH API on iPhone

I know how to post an image using the GRAPH API and I know how to post a comment using the same. But I can't figure out how to post a photo and allow the user to also include a message/status with the photo (all posting on the user's own wall).
This is the code that I am using to upload a photo from my app to user's wall. The GRAPH API does not define what other keys I can specify in the param dictionary.
-(void) uploadPhotoToFacebook {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imageView.image, #"picture", nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
I have found ways to do this using the now deprecated Facebook API but that doesn't help me.
Thanks for the help,
// Post a status update along with picture via the Graph API, and display an alert view
with the results or an error.
NSString *message = #"This is status Message!";
UIImage *image = [UIImage imageNamed:#"myPngImageToPost"];
NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:message, UIImagePNGRepresentation(image), nil] forKeys:[NSArray arrayWithObjects:#"message", #"picture", nil]];
// use the "startWith" helper static on FBRequest to both create and start a request, with
// a specified completion handler.
[FBRequest startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:message result:result error:error];
}];
The above code will show status update as well as image below your status message.
The documentation is here: http://developers.facebook.com/docs/reference/api/photo/ ... along with the restrictions and required permissions. I have been wrestling with it for a few days since not everything I expect to work works! For posting you want to use the "source" key instead of picture which refers to the thumbnail.
Posting on the wall (feed dialog) and comments (graph photo/comment) (comments and tags are adding connections) are all separate transactions. For posting, I'm struggling with it since I can post a photo by providing an existing URL from another website but for some reason, I cannot point use the photo link from the picture I just posted (the feed dialog appears without any photo).

Calling FQL queries from the iPhone fbconnect libraries

I started developing an iPhone application in June 2010 that used the Facebook APIs extensively. I logged in and got a FBSession which contains the logged in user's profile id, etc. I then used the FBRequest class to make many calls using the FQL to get data.
How do I call FQL queries from the latest Facebook Connect APIs?
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"SELECT uid,name FROM user WHERE uid=4", #"query",
nil];
[_facebook requestWithMethodName: #"fql.query"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];