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

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];

Related

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

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.

How to post on user's wall indicating an app was installed?

http://developers.facebook.com/docs/reference/api/post/ doesn't seem to give a clue about it. Would "Install(ed)" be an action? If the feed is something like " installed on iPhone", how to make the to be a link such that the user can tap on it so to lead the user to App Store?
I know the API to use, something like the following. But I just don't know what are the params that should be there for the above feed.
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithCapacity:1]
[params setObject:username forKey:#"name"];
[params setObject:#"Description" forKey:#"description"];
[facebook requestWithGraphPath:#"me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
You can get all info of setting the facebook ios sdk with a screenshot of a post..
http://developers.facebook.com/docs/mobile/ios/build

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).

Facebook Connect on iOS - Picture doesn't display with wall post

I've set up Facebook connect with my app using the demo project provided by Facebook. Everything works great, except for the last little step...
First of all, I login and get permissions.
Next, I upload a picture. This works great, I can see the picture in my Facebook album like I should be able to.
When this picture is uploaded, I get it's URL (returned by the FBRequest delegate). Copy pasting this URL into a web browser takes me directly to the image, so I know that this URL is correct.
Here's where the problem is:
I now want to present this picture alongside a wall post. The wall post is fine, but the picture just doesn't seem to attach and the status is left as a plain text message.
Here's the code I'm using for the last part:
- (void)request:(FBRequest *)request didLoad:(id)result {
NSString* picUrl = [result objectForKey:#"src_big"]; //this definitely returns the right URL
if (picUrl)
{
NSString *message = #"Test status";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
message, #"message", picUrl, #"picture", #"Look at my photo", #"name", nil];
[facebook requestWithMethodName:#"facebook.Stream.publish" andParams:params
andHttpMethod:#"POST" andDelegate:self];
}
}
Any ideas what I'm missing or doing wrong?
Fixed with the following code (after a lot of failed attempts). Facebook doesn't like the way I was trying it, you've got to do it all in just one step:
NSData *imageData = UIImagePNGRepresentation(image);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test message", #"message", imageData, #"source", nil];
[facebook requestWithGraphPath:#"/me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];
Can't comment yet but to get this working I had to change #"/me/photos" to #"me/photos" in Jordan's answer above. Very helpful though, not sure why it was down voted.

How to publish the content in facebook of iphone

I am new to iphone development.I have created facebook application and i have displayed the login page and publish page. now i want to share my content(title and summary) display dynamically.
i dont know how to give the contents dynamically,
Here my code and display statically, it will published.
but i want to give my contents dynamically displayed.
titles and summaries are stored in the mutable arrays.
NSString *art;(titles are stored)
NSString *summ; [Summary are stored];
fbAgent.shouldResumeSession =YES;
[fbAgent publishFeedWithName:#"Sample"
captionText:#"Test Application"
imageurl:#"http://amanpages.com/wordpress/wpcontent/uploads/2009/12/logo2.png"
linkurl:#"http://www.yahoo.com"
userMessagePrompt:#"Share Something about this article"
actionLabel:nil
actionText:#"Search Google"
actionLink:#"http://wwww.google.com"];
This sample code and downloaded in the net. now i want to shared to publish title and summary.
Plz help me out,
Using the fbagent, you cannot publish title+description only, you have to also provide a link to an image and a webpage url.
The image can be your iPhone app icon stored on your site and webpage url can be appstore download link of your iPhone app.
This will help popularize and advertise your app.
So, minimum you can do is:
fbAgent.shouldResumeSession = YES;
[fbAgent publishFeedWithName:art
captionText:summ
imageurl:#"http://amanpages.com/wordpress/wp-content/uploads/2009/12/logo2.png"
linkurl:#"http://amanpages.com/"
userMessagePrompt:#"What do i think:"];
Hope it helps.
just check this example:
NSMutableDictionary* params1 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
appId, #"api_key",
#"Happy Holi", #"message",
#"http://www.holifestival.org/holi-festival.html", #"link",
#"http://www.onthegotours.com/blog/wp-content/uploads/2010/08/Holi-Festival.png", #"picture",
#"Wanna Kno abt HOLI.. Check this...", #"name",
#"Wish u 'n' Ur Family, a Colourful day...", #"description",
nil];
[facebook requestWithGraphPath:#"me/feed" andParams:params1 andHttpMethod:#"POST" andDelegate:self];
It will publish to your wall. If you want to publish to friends wall,then replace 'me' with [friend facebook UID].
[facebook requestWithGraphPath:#"1908979/feed" andParams:params1 andHttpMethod:#"POST" andDelegate:self];