Facebook: get url of uploaded photo - iphone

I am working on an Iphone application and I am using facebook sdk to post on a user's wall.
I need to create a post with a text and a picture.
For that first I am uploading the picture to the user's profile by using this:
//image to post is the UIImage I am uploading
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self imageToPost], #"picture"
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}
This is working corretly. The result I get is in the following format:
{
id = 101586254325716;
"post_id" = "100004123442691_101551541234190";
}
Now I want to post a feed on the user wall containing a text and the image uploaded.
//self.facebookStatus is the text I want to post
//imageURL is the url of the image
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.facebookStatus, #"message",
imageURL, #"picture",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}
Problem:
I dont know what the imageURL should be. I tried to use the id or post_id I get as a result but it is not working. I alst tried www.facebook.com/101586254325716 but didn't work either.
How can I get the url of the image I uploaded in order to add it to the wall post?
Thanks
PS: If someone has other ways or hints on posting on a users wall, text + image from the iphone That would be great.

In the params dictionary that you're using to post the image add another object, like this:
[params setObject:self.facebookStatus forKey:#"message"];
that should be enough to post both the picture and the text

It turns out that I have to use the object_attachment parameter and set it to the photo id
and not the picture parameter.
Will leave it here in case someone had the same problem

Related

Post a photo to an Album on a Facebook fan page without being the admin,

From my iOS application, i would like to post a photo to a fan page where i am not the admin.
I am doing well with that code:
NSData* imageData = UIImageJPEGRepresentation(image_, 90);
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"hello", #"message",
imageData, #"source",
accessToken, #"access_token",
nil];
[FBRequestConnection startWithGraphPath:#"{pageID}/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
DLog(#"error %#",error);
DLog(#"result %#",result);
}];
But now, i want to that photo comes to a specific album of the fan page. I tried to specify the "albumId" like at the Path: {albumID}/photos. It post it correctly but to my wall an not in a album of the fan page.

Facebook error getting image on post [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to post photos to facebook iphone fbconnect
I am using FB SDK and getting an error while uploading picture on FB post from my app
in my view did load i have and UIImageView which has an image that i need to be posted on FB the code of the view did load
ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 65, 65)];
ImageView.center = CGPointMake(42, 43);
[View addSubview:ImageView];
and in my method of FB post i did this
UIImage *image = [[UIImage alloc]init];
image = ImageView.image;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:3];
[params setObject:#"LINK_HERE" forKey:#"link"];
// due to this line below, i am getting an error :
// "[UIImage length]: unrecognized selector sent to instance 0x170fa0e0"
// and if use http link instead of image(UIImage) it works, but i want to use my image
[params setObject:image forKey:#"picture"];
[params setObject:#"NAME_HERE" forKey:#"name"];
[params setObject:#"DEC_HERE" forKey:#"description"];
// Invoke the dialog
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
How should i use my UIImage inside this code ... any idea ??
You can only upload URL based images in Facebook dialog method..Images generated within the app or within app bundle cant be uploaded..
To upload those images you have to use graph API
sample code
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, #"source",
#"caption desc", #"message",
nil];
[facebook requestWithGraphPath:[NSString stringWithFormat:#"/me/photos?access_token=%#", self.facebook.accessToken]
andParams:params andHttpMethod:#"POST" andDelegate:self];
you can post your image simply like this
UIImage *imgSource = {insert your image here};
NSString *strMessage = #"Images Description";
NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
imgSource,#"source",
strMessage,#"message",
nil];
[self.facebook requestWithGraphPath:#"me/photos"
andParams:photosParams
andHttpMethod:#"POST"
andDelegate:self];
There is a sample app in facebook sdk, please check that.
You can also check out these tutorials:
Facebook Tutorial for iOS: How To Use Facebook’s New Graph API from your iPhone App
Facebook Tutorial for iOS: How To Get a User Profile with Facebook’s New Graph API from your iPhone App
Facebook Tutorial for iOS: How To Post to a User’s Wall, Upload Photos, and Add a Like Button from your iPhone App

Post a link to Facebook including an UIImage

I want to post a link including an image to Facebook timeline:
UIImage *img = [UIImage imageNamed:#"1.png"];
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"Here we go", #"message",
#"https://developers.facebook.com/ios", #"link",
UIImagePNGRepresentation(img), #"picture",
#"Facebook SDK for iOS", #"name",
#"Build great social apps and get more installs.", #"caption",
#"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", #"description",
nil];
[FBRequestConnection startWithGraphPath:#"me/feed" parameters:self.postParams HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self showAlert:#"Link is posted" result:result error:error];
}];
The UIImage does not posted. Can you help me?
But simply if I use :
#"https://developers.facebook.com/attachment/iossdk_logo.png", #"picture"
it works.
If you read the documentation, it says the "picture" parameter should be of type string ie: a url. You can not post an image and a message from the mobile SDKs at the same time without some clever hackory: see me/photos in the documentation but your options are severely limited.

FBConnect iphone : I coud'nt get Photos albums for some account ?

Maybe someone can't help me.
I use the last FBConnect (http://github.com/facebook/facebook-ios-sdk/) for Facebook connexion.
And I retreive the list of photos albums for the user.
NSMutableDictionary* params = [NSMutableDictionary NictionaryWithObjectsAndKeys:_facebook.accessToken,#"access_token",nil];
[_facebook requestWithGraphPath:#"me/albums" andParams:params andDelegate:self];
I'm testing with 4 differents account with all the same rules for privacy (Account/Privacy settings). And for some of them the albums list is empty ? And if i test via a webbrowser on a desktop computer (https://graph.facebook.com/me/albums) for account who doesn't work on iphone, the list is not empty ?
On iphone, i use graph api or FQL with same results ("SELECT aid FROM album WHERE owner = me()")
Maybe i miss some think about configuration off the facebookapp ?
Thanks for answer.
I resolve the solution with good settings for facebook authentifications
http://developers.facebook.com/docs/authentication/permissions
THIS WILL PUT ALL THE IMAGES OF THE ALBUM IN SOURCE ARRAY!
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/photos&access_token=AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UpZBqNxpgw62zWSlhSYyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD",A_ID]];
URLWithString:#"https://graph.facebook.com/114750591966408/photos&access_token=//AAACeFkezepQBANpoFq9I3Hts0JdE6Xis3UyYcluGaaxH3IlKIh9w8OYrXYF9MsAxhk6ta1ANZClCaznpdSaERgZDZD"];
NSData *data1 = [NSData dataWithContentsOfURL:url1];
NSString *str1=[[NSString alloc] initWithData:data1 encoding:NSASCIIStringEncoding];
// NSString *str1=[[NSString alloc]ini]
NSDictionary *userData1 = [str1 JSONValue];
NSArray *arrOfimages=[userData1 objectForKey:#"data"];
NSMutableArray *sourceUrls = [[NSMutableArray alloc] initWithCapacity:0];
for(NSDictionary *subDictionary in arrOfimages)
{
[sourceUrls addObject:[subDictionary objectForKey:#"picture"]];
}
publish_actions and user_photos permissions is required.
And then please try the following code :
[FBRequestConnection startWithGraphPath:#"me/albums"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Success! Include your code to handle the results here
NSLog(#"user events: %#", result);
NSArray *feed =[result objectForKey:#"data"];
for (NSDictionary *dict in feed) {
NSLog(#"first %#",dict);
}
} else {
// An error occurred, we need to handle the error
// Check out our error handling guide: https://developers.facebook.com/docs/ios/errors/
NSLog(#"error %#", error.description);
}
}];

Facebook graph api with native iPhone application

I want to use the Facebook Graph API in a NATIVE iPhone Application. Has anybody been able to find a way to post images/message on a user's feed?
I have tried all possible ways to post a ‘picture’ (not a URL but a UIImage) on the feed and have been working on this for 2 weeks now.
If you go to facebook.com you can upload a picture from your computer on to the wall. I am using ASIHTTPRequest to work on facebook graph API.
This is the nearest I have gone to posting a picture on the feed. So if I have a ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
The url is https://graph.facebook.com/me/feed
Now to post a picture I do the following:
[request setPostValue:#"My Message" forKey:#"message"];
[request setPostValue:#"somepic.png" forKey:#"picture"];
[request setPostValue:#"Some Name" forKey:#"name"];
[request setPostValue:#"Some description" forKey:#"description];
[request startAsynchronous];
If you try this then everything works fine other than the picture being posted. A blank placeholder for the picture is though show on the feed.
I created a method to help me do this. Hope this is of some help.
Please read the tutorial on how to set up the Facebook SDK.
-(void) updateStatusWithText:(NSString *) fbTitle //Status title
andStoryURL:(NSString *) fbURL //URL for the story
andStory:(NSString *) fbStory //The story
andImage:(NSString *) imageURL //Image to be displayed.
andPrompt:(NSString *) promptString{
NSLog(#"updateStatusWithText");
NSString *attachmentText =[NSString stringWithFormat:#"{\"name\":\"%#\","
"\"href\":\"%#\","
"\"description\":\"%#\","
"\"media\":[{\"type\":\"image\","
"\"src\":\"%#\","
"\"href\":\"%#\"}],"
"\"properties\":{\"Uploaded from an iPhone\":{\"text\":\"AFL Fan\",\"href\":\"Your itunes apstore URL\"}}}", fbTitle, fbURL, fbStory,imageURL,fbURL];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
promptString, #"user_message_prompt",
// actionLinksStr, #"properties",
attachmentText, #"attachment",
nil];
NSLog (#"attachmentText : %#", attachmentText);
[facebook dialog:#"stream.publish"
andParams:params
andDelegate:self];
}