【问题标题】:Upload photo using new iOS Facebook SDK API (3.0)使用新的 iOS Facebook SDK API (3.0) 上传照片
【发布时间】:2012-08-15 18:30:13
【问题描述】:

如何使用他们的新 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];
    }];
}

【问题讨论】:

    标签: objective-c ios facebook facebook-ios-sdk


    【解决方案1】:

    你的代码没问题,需要做一些小改动:

    将图片以NSData格式添加到字典中,比如

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

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

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

    【讨论】:

    • 您能否澄清“我/照片”和“我/饲料”之间的区别。比如我们什么时候需要使用其中的哪一个。还有哪些其他选项可用。能不能详细解释一下。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      相关资源
      最近更新 更多