Post a photo to a page for iOS - iphone

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.

Related

Facebook permissions required to tag a friend in a wall post..?

I want to tag a friend in a post which I am posting on my wall , just wanted to know what permissions are required...?
I am using the following code...
For permissions..
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"friends_online_presence",
#"read_stream",
#"email",
#"publish_stream",
nil];
[self.appDelegate.facebook authorize:permissions];
[permissions release];
and to post
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Test 2",#"message",
#"100004311843201,1039844409", #"to",
nil];
[self.appDelegate.facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
This gets posted on wall successfully but the profile ids are not included...
Though its in PHP here is bug report which says it is problem in Graph API while posting status update and tagging friends is not working properly.
It says that it will post status update but tagging is not working.
EDIT:
As discussed with OP in comments, adding place field attached to parameters it is working.
I think this should help you:
To mention a user in a user message, place this string inline with the message: #[userID] or #[profileUrl]. This creates an inline hyperlink to the profile of the mentioned friends and sends them a notification that they have been tagged.
Taken from: https://developers.facebook.com/docs/technical-guides/opengraph/mention-tagging/
For tag friends in Facebook friends id are required to tag in post etc.
customer friend picker is better for tag friends.
see below Facebook sample
https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2178-6/851564_497226807066458_2037734970_n.png
for this purpose us this graph api taggable_friends to get tag able friends
for more detail visit this link and read tag section (Mention Tagging is suite for your requirements)
mentiontagging detail info

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.

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

How to use FBConnect dialog method to post a UIImage to my wall?

(Note: I've looked all over for this, and there are tons of examples for how to post a URL-to-image via dialog, and a few for how to post image-data direct to photo album, but neither of those are what I'm trying to do.)
I can post an image that's stored on the web easily enough with code similar to this:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"This is what I say about kittens!", #"message",
#"Kittens!", #"name",
#"I'm feeling fuzzy", #"caption",
#"You, too, can feel fuzzy, with FuzzyKittenâ„¢", #"description",
#"http://example.com/fuzzykitten.html", #"link",
#"http://placekitten.com/200/150", #"picture",
nil];
[facebook dialog: #"feed"
andParams: params
andDelegate: self];
And everything works fine. The problem is, I'd like to replace:
#"http://placekitten.com/200/150", #"picture",
with something along the lines of:
[UIImage imageNamed: #"myImage.png"], #"picture",
which, of course, isn't right. So my question is: If I have an image in UIImage form, how do I load that into the parameters dictionary to pass to the dialog method?
Thanks!
EDIT: This is a client iPhone app for which there is no server so, while uploading the image to FB as part-1 of a 2-part process is fine, I'm now not seeing how to find the uploaded image's URL. Thanks again!
You can't directly upload an image to the wall, when publishing to the wall you can just link an image to it.
So, you need to upload the UIImage somewhere first. You have 2 options:
1. Upload to your/some server and publish a wall post linking to it.
2. Upload to a facebook album. Check the graph API about doing that, it is pretty straightforward.
edit: you can no longer source images hosted in facebook CDN (and probably other CDNs), so if you need to link an image from a dialog you should upload it on a server and get a permalink from there
You could use ASIFormDataRequest and run a script to upload your file to your server using something like this:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
// Upload a file on disk
[request setFile:#"/Users/ben/Desktop/ben.jpg" withFileName:#"myphoto.jpg" andContentType:#"image/jpeg"
forKey:#"photo"];
Then have the ASIFormDataRequest's response return the url of the uploaded image to your application.
You can use the event of the ASIFormDataRequest response to trigger the Facebook image post.