我正在尝试在我的 iPad 应用程序中的 Facebook 墙上发布一张图片。但什么都没有发生,Facebook 网站弹出允许它,但从未发布图像。这是我的代码:
-(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];
}