Upload an image on Facebook via FBConnect - iphone

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.

Related

Facebook like button in iPhone native app

I want to implement facebook like button in my native iphone app. So that user can like my facebook page . I am already sharing facebook status updates, but am unable to implement like button.
I was unable to find any helpful resource on web.Please help.
Aaaand here's one I prepared earlier (using FBConnect, the FB api):
If you have the id of the post as postId
NSString *graphPath = [[NSString alloc]
initWithFormat:#"%#/likes",
postId];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[[delegate facebook] requestWithGraphPath:graphPath andParams:params andHttpMethod:#"POST" andDelegate:self];
of course you'd need to change how you got the Facebook singleton (I used [delegate Facebook]).

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

postToWall on facebook After login in iphone

Does anybody have idea about how to post a wall on
facebook after login button in iphone.
i have to post default image and text.
If yes in which fb class it have to write .i have latest sdk for facebook.
Thanks
using FBConnect library after login you can use the following method to post on the users wall
Facebook *facebook = [[[UIApplication sharedApplication] delegate] facebook];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"###yourAPIKeY###", #"api_key",
#"###Your Message###", #"message",
#"###link if you want###", #"link",
#"### a picture if you want###", #"picture",
#"###name of your fb app###", #"name",
#"###Description###", #"description",
nil];
[facebook requestWithGraphPath:#"me/feed"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
If you want it to happen right after the user logged in it should be implemented in the following method:
-(void) fbDidLogin
{
}
be sure to note that you need to ask from the user publish_stream permissions

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.