简体   繁体   English

在Facebook墙上张贴图片

[英]Posting a picture on Facebook wall

I'm trying to post a picture on a Facebook wall in my iPad app. 我正在尝试在iPad应用程序的Facebook墙上张贴图片。 But nothing is happening, the Facebook site pops up to allow it, but an image is never posted. 但是什么也没发生,Facebook网站弹出来允许它,但从未发布过图像。 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];
}

You have put the post parts in the fbDidLogin method. 您已将零件放置在fbDidLogin方法中。

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. 同样,这与您的问题完全无关,但是我在您发布的代码中注意到了这一点,您不必将图像转换为NSData,如果您希望可以将UIImage本身放在关键picture ,将被上传。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM