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.
Related
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.
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
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
I have upload images with url image successful on this way
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"https://developers.facebook.com/docs/reference/dialogs/", #"link",
#"http://fbrell.com/f8.jpg", #"picture",
#"Facebook Dialogs", #"name",
#"Reference Documentation", #"caption",
#"Using Dialogs to interact with users.", #"description",
nil];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[delegate facebook] dialog:#"feed"
andParams:params
andDelegate:self];
Now i want to upload image from a local image in same way
like
profImg = [UIImage imageNamed:LoginWithFacebookNormal#2x.png"];
NSData *data = [NSData dataWithData:UIImagePNGRepresentation(profImg)];
i have used data, #"picture", in dictionary but it's give me error
is it any other way to upload local/Gallery/resource image with dialog box + comment area ?
I have searched but every time found that only url image can feed the dialog box
I have used Hackgraph tutorial for this posting.
Note: I am not using Sharekit or any other API i have used only Graph API
Finally after lots of research I get the example of Facebook. Download the example from here. You have to make modification because currently example hold static image.
i've configured FBConnect and it uploads to the wall, but what i want to do is take a screenshot and then upload the screenshot to FB.
In the below code there is an image but as a url. Can i intersect this and put in my screenshot image?
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]autorelease];
dialog.userMessagePrompt = #"Tell your friends about Fridgit!!:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.phptab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"screenShot\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}", self.screenShot];
[dialog show];
}
i know all the code is default i haven't edited it yet incase i can't do what i want to do.
Cheers
Yes its possible with the new FB API nw, they made it as simple as possible
// code snippet to take a snapshot
// REF: http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
[_facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];