views:

1710

answers:

5

Hello

I found out how to send some text on the user's wall, with the FBConnect API, on iphone. I even found how to put an image already on the internet :

FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 12345;
dialog.templateData = @"{\"image\":[{\"src\":\"http://sample.png\",\"href\":\"http://sample.com\"}] }";
[dialog show];

(see http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone)

But I can't figure out how to upload an UIImage from my iphone to the user's wall with FB Api. Do I have, first, to upload the image on any website, then put its url in the templateData ? Isn't there any simpler solution ?

Thanks.

Martin

+1  A: 

Use the below function to upload the image, pass the UIImage as the parameter, it will work.

- (void)uploadPhoto:(UIImage *)uploadImage
{
    NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
    [args setObject:uploadImage forKey:@"image"];    // 'images' is an array of 'UIImage' objects
    [args setObject:@"4865751097970555873" forKey:@"aid"];// this should be album id
    uploadPhotoRequest = [FBRequest requestWithDelegate:self];
    [uploadPhotoRequest call:@"photos.upload" params:args];

    NSLog(@"uploading image is successful");
}
Thanks a lot for the code.So you have two steps : first the upload, secondary the templateData.Is there, on Facebook server, some places where you can put this kind of data ?
Martin
A: 

Is there a way to just post picture to wall without album id?

HARDWARRIOR
This is not an answer to the asked question. Please start your own question.
SooDesuNe
A: 

It is not working for me, with the following code, it always crashes

UIImage *imageToSend = [UIImage imageNamed:@"angrybagTN.png"];
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:imageToSend forKey:@"image"];//need to specify image
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:@"photos.upload" params:args];

Any idea?

A: 

[[FBRequest requestWithDelegate:self] call:@"facebook.photos.upload" params:params dataParam:(NSData*)img;

and pass params to nil . it will upload image to default album

A: 

is there any way to upload a picture and set it as a profile picture ????

yunas