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

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

于 2013-03-30T19:34:37.593 に答える