2012-08-15 11 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

「me/photos」は、実際にあなたのFacebookプロフィールの「写真」リストにある写真を意味します。 「私/フィード」はタイムラインの単なる投稿です。

12

あなたのコードは、若干の変更が行われなければ結構です。

NSData形式で辞書に画像を追加し、

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

などグラフパスを"me/feed"の代わりに"me/photos"に変更してください。

これらの変更を行うと、私にとっては効果があります。 "publish_actions"のアクセス許可を使用する必要があることを覚えておいてください。

+0

"me/photos"と "me/feed"の違いを明確にしてください。いつのように私たちはどちらを使う必要がありますか?さらに他のオプションもあります。少し詳しく説明してください。 – Satyam