Reputation: 527
I'm trying to post a picture on a Facebook wall in my iPad app. But nothing is happening, the Facebook site pops up to allow it, but an image is never posted. This is the code I have:
-(IBAction)facebookButton {
facebook = [[Facebook alloc] initWithAppId: APP_ID andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
[facebook authorize:[NSArray arrayWithObjects: @"publish_stream",@"user_photos", nil]];
UIImage* image = [UIImage imageNamed: @"image.png"];
NSData* imgData = UIImagePNGRepresentation(image);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Hey", @"message", //whatever message goes here
imgData, @"data", //img is your UIImage
nil];
[facebook requestWithGraphPath:@"me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
Upvotes: 0
Views: 358
Reputation: 13773
You have put the post parts in the fbDidLogin
method.
Also, this is completely irrelevant to your question, but it's something I noticed with the code you posted, you don't have to convert the image to NSData, if you want you can put the UIImage itself in under the key picture
and it'll be uploaded.
Upvotes: 1