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

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.

Related

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

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

i want to share friend's post via graph api

I want to share some posts in facebook via graph api.
But there's no api like this. only "feed" exists.
I tried to use "me/feed" graph api action to share my friend's post(and post in page). but it's not same as i shared in facebook website. i want to know how.
source is..
NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];
NSString *linkURL = #"http://media.daum.net/society/others/view.html?cateid=1067&newsid=20120106140112792&p=munhwa&RIGHT_COMM=R4";
[fbArguments setObject:linkURL forKey:#"link"];
[facebook requestWithGraphPath:#"me/feed"
andParams:fbArguments
andHttpMethod:#"POST"
andDelegate:self];
[fbArguments release];
And I noticed there's no action for sharing friend's post(or photo), page's post via facebook iphone app. (so weird. don't you need this action?)
what can i do? can you help me?
Thanks.
i'v succeeded sharing photo. that is 'Link'.
source is
NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];
NSString *linkURL = #"https://www.facebook.com/photo.php?fbid=324225380935287&set=a.265279620163197.68309.194442110580282&type=1";
[fbArguments setObject:linkURL forKey:#"link"];
[fbArguments setObject:#"good!" forKey:#"message"];
[facebook requestWithGraphPath:#"me/feed"
andParams:fbArguments
andHttpMethod:#"POST"
andDelegate:self];
[fbArguments release];
i added message. and this is perfectly same as i shared via facebook web.
but there is one problem. this never makes back reference(trackback?).
if I share a photo via facebook web, I can see "5 shares" upper comment list, and my username is is there.
But this way, There is no my username. No trackback.
what can i do?
thanks.

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

Upload an image on Facebook via FBConnect

I know many question has been post and answer for this question. I still stuck by a little thing.
I did success upload an UIImage on Facebook via my iPhone app but I realize that photos goes to a pending album. And user had to accept it to get it post on their wall.
Here is my code
- (void)start
{
NSArray *permissions = [NSArray arrayWithObjects:
#"read_stream", #"offline_access", nil];
[_fbEngine authorize:kFbAppId
permissions:permissions
delegate:self];
}
#pragma mark -
#pragma mark FBSession delegate
- (void)fbDidLogin
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.image, #"picture",
nil];
[_fbEngine requestWithMethodName:#"photos.upload"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
Is there a way to post a photo directly on the wall without passing by the pending album.
Regards,
KL94
Add #"publish_stream" to your list of requested permissions.
That'll let you push straight to their wall without an intermediate step. #"offline_access" would allow you to do that via the graph api instead of with a FBDialog, too, so you could make the post happen entirely in the background.