2012-10-15 25 views
1

我试图上传文字与图像使用FBRequestConnection像如下,但我只能够上传文字,而不是图像。 但是,当我给任何图像链接代替img1(图片),然后我能够在Facebook墙上看到图像。如何使用FBRequestConnection将文本上传到Facebook的图片?

UIImage *img1 = [UIImage imageNamed:@"[email protected]"]; 

NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys: 
           @"https://developers.facebook.com/ios", @"link", 
           img1, @"picture", 
           @"Facebook SDK for iOS", @"name", 
           @"build apps.", @"caption", 
           @"imagae description.", @"description", 
           nil]; 


[params setObject:@"post message" forKey:@"message"]; 


[FBRequestConnection 
startWithGraphPath:@"me/feed" 
parameters:params 
HTTPMethod:@"POST" 
completionHandler:^(FBRequestConnection *connection, 
        id result, 
        NSError *error) { 
    NSString *alertText; 
    if (error) { 
     alertText = [NSString stringWithFormat: 
         @"error: domain = %@, code = %d", 
         error.domain, error.code]; 
    } else { 
     alertText = @"Posted successfully."; 
    } 
    // Show the result in an alert 
    [[[UIAlertView alloc] initWithTitle:@"Result" 
           message:alertText 
           delegate:self 
         cancelButtonTitle:@"OK!" 
         otherButtonTitles:nil] 
     show]; 
}]; 

我已经采取了两个许可@ “publish_actions”,@ “user_photos”

请让我知道我错了,在此代码。

回答

2

将@“图片”更改为@“源”。 如果你使用的是新的Facebook 3.1 SDK,你可以做得更简单:

FBRequest *req = [FBRequest requestForUploadPhoto:img1]; 
[req.parameters addEntriesFromDictionary:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"post message", @"message", nil]]; 

FBRequestConnection *con = [[FBRequestConnection alloc] init]; 
[con addRequest:req completionHandler.... 
+0

目前需要使用“caption”而不是“message” – AlexeyVMP

相关问题