5

如何使用他们的新 API/SDK 从 iOS 应用程序将照片上传到 Facebook?我已经尝试过了,但我没有得到任何地方,只是继续绕圈跑。这是我目前拥有的代码:

-(void)dataForFaceboo{
    self.postParams =
    [[NSMutableDictionary alloc] initWithObjectsAndKeys:
     self.uploadPhoto.image, @"picture", nil];
}

-(void)uploadToFacebook{

    [self dataForFacebook];

    NSLog(@"Going to facebook: %@", self.postParams);

    // Hide keyboard if showing when button clicked
    if ([self.photoCaption isFirstResponder]) {
        [self.photoCaption resignFirstResponder];
    }
    // Add user message parameter if user filled it in
    if (![self.photoCaption.text
        isEqualToString:kPlaceholderPostMessage] &&
        ![self.photoCaption.text isEqualToString:@""]) 
    {
        [self.postParams setObject:self.photoCaption.text forKey:@"message"];
    }
    [FBRequestConnection startWithGraphPath:@"me/feed"
        parameters:self.postParams
        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 = [NSString stringWithFormat:
                         @"Posted action, id: %@",
                         [result objectForKey:@"id"]];
        }
        // Show the result in an alert
        [[[UIAlertView alloc] initWithTitle:@"Result"
                              message:alertText
                              delegate:self
                              cancelButtonTitle:@"OK!"
                              otherButtonTitles:nil] show];
    }];
}
4

2 回答 2

12

您的代码很好,需要进行一些细微的更改:

NSData以格式将图像添加到字典中,例如

[params setObject:UIImagePNGRepresentation(_image) forKey:@"picture"];

并将图形路径更改为"me/photos"而不是"me/feed"

进行这些更改,它对我有用。请记住,您需要使用“publish_actions”权限。

于 2012-08-16T12:23:03.903 回答
0

“我/照片”是指照片实际上位于您 Facebook 个人资料的“照片”列表中。“我/饲料”只是时间线上的一个帖子。

于 2013-03-30T19:34:37.593 回答