image upload on facebook connect iphone
I am new to iphone app development, and I am trying to upload images on Facebook through our iphone apps. I have tried the below code which is using fbconnect, but it is not working.
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:fbimages forKey:@"image"]; // 'fbimages'(it is having 2 images) is an array of 'UIImage' objects..
FBRequest *uploadPhotoRequest = [[[FBRequest alloc] init] autorelease];
uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:@"facebook.photos.upload" params:args];
//[[FBRequest requestWithDelegate:self] ca开发者_如何学编程ll:@"facebook.photos.upload" params:args];
NSLog(@"uploading image is successful");
Finally i found the solution for upload images on facebook from iphone. Use below code. It will work sure.
- (void)uploadPhoto{
NSMutableDictionary *args = [[NSMutableDictionary alloc] init];
UIImage *img = [UIImage imageNamed:@"picture1.jpg"];
NSData *data = UIImageJPEGRepresentation(img, 10);
//NSData *data = UIImagePNGRepresentation(img);
NSString *imgstr = [data base64Encoding];
//NSString *imgstr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
//[args setObject:[UIImage imageNamed:@"antartica1.png"] forKey:@"image"];
[args setObject:imgstr forKey:@"image"]; // 'images' is an array of 'UIImage' objects
uploadimgrequest = [FBRequest requestWithDelegate:self];
[uploadimgrequest call:@"photos.upload" params:args dataParam:data];
//[uploadimgrequest call:@"photos.upload" params:args];
}
get this code !!!!
YUVARAJ.M
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Uploaded thru app", @"message", nil];
[params setObject:[UIImage imageNamed:@"image-name.png"] forKey:@"source"];
[facebook requestWithGraphPath:@"me/photos"
andParams: params
andHttpMethod: @"POST"
andDelegate:self];
Here i answered for my question, which is using FBConnect for Facebook image uploading. It was a correct answer for my own question. But, now i heard FBConnect may not valid in future Facebook connection for mobile application. So, now am replaced FBGraph API for FBConnect. SO, you guys please omit FBConnect and try to use Graph API. It is mush easier than FBConnect.
You need to use all delegates for FBSession and FBRequest delegates for FBConnect... I just called uploadPhoto method from FBRequest delegate.. Below is my code... Use this code...
- (void)request:(FBRequest*)request didLoad:(id)result {
if ([[request method] isEqual:@"facebook.fql.query"]) {
NSArray* users = result;
NSLog(@"users %@",users);
NSDictionary* user = [users objectAtIndex:0];
NSLog(@"user %@",user);
[self uploadPhoto];
}
}
Just a quick side note - you should try out ShareKit. It is absolutely amazing and makes all interactions with Social Media sites a doddle. The library is open source and easily extensible/customisable.
Try it and see what you think:
ShareKit home site
精彩评论