2012-08-15 78 views
5

如何使用新的API/SDK从iOS应用程序上传照片到Facebook?我已经试过了,我没有得到任何地方,只是继续在圈子里跑。下面是代码我目前有:使用新的iOS Facebook SDK API上传照片(3.0)

-(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]; 
    }]; 
} 

回答

0

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

12

你的代码是好的,做了一些细微的变化:

图像添加到字典中NSData格式,像

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

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

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

+0

请您澄清“我/照片”和“我/喂”之间的区别。就像什么时候我们需要使用哪一个一样。还有更多其他选项可用。你能详细解释一下吗? – Satyam 2013-01-11 13:58:08

相关问题