0

こんにちは、私はこのコードを使用してFacebookに画像を投稿しています

UIImage *image_LocalSharePhoto = [[UIImage alloc]initWithData:sharedSingleton.dataResultImage];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"Put Captions On Pics", @"name",
                            @"Put Captions On Pics", @"caption",
                            image_LocalSharePhoto,@"picture",
                            @"I created this fun photo using a FREE app http://bit.ly/CapsPics. #PutCapsOnPics via @PutCapsOnPics", @"description",
                            nil];

NSString *attachmentStr = [jsonWriter stringWithObject:attachment];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"532872463436844", @"api_key",
                               @"Share on Facebook",  @"user_message_prompt",
                               attachmentStr, @"attachment",
                               nil];

[facebook dialog: @"feed" andParams:params andDelegate:self];

Facebookページが開きますが、共有または投稿するものは何も表示されません. 誰かが助けることができますか。ありがとう!

4

2 に答える 2

2

facebook の api を使用している場合、次のコードを使用してユーザーのタイムラインで画像を共有できます...コードが役立つ場合は、コードを確認してください..

// aryFetchedImages = Array of images which needs to be posted on Facebook
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
for (int i = 0; i < aryFetchedImages.count ; i++)
{
        [params setObject:UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f)  forKey:@"picture"];
        [FBRequestConnection startWithGraphPath:@"me/photos"
                                     parameters:params
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection,
                                                  id result,
                                                  NSError *error)
         {
             if (error)
             {
                 //showing an alert for failure
                #ifdef DEBUG
                    NSLog(@"Unable to share the photo please try later - Fail %@",error);
                #endif
             }
             else
             {
                 //showing an alert for success
                #ifdef DEBUG
                    NSLog(@"Photo %@ uploaded on Facebook Successfully",UIImageJPEGRepresentation([aryFetchedImages objectAtIndex:i], 50.0f));
                #endif

             }
         }];
}
于 2013-06-18T08:49:26.777 に答える
1

古い Facebook メソッドを使用している場合は、以下の方法のように壁に投稿できます:-

NSArray* permissions = [NSArray arrayWithObjects:@"publish_stream", @"user_photos", nil];
    [facebook authorize:permissions];

ボタンをクリックするか、次のようなロジックで画像を投稿します:-

 -(IBAction)ActionPostWallPhoto
    {

         NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                               ImageView.image, @"picture",
                                               nil];

        [[objAppdele facebook] requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

    }

新しいFacebook APIを使用している場合は、次のメソッドを使用できます:-

 NSMutableDictionary *postTest = [[NSMutableDictionary alloc]init];
        [postTest setObject:[NSString stringWithFormat@"Your message"] forKey:@"message"];
        [postTest setObject:@"" forKey:@"picture"];
        [postTest setObject:@"" forKey:@"name"];
        [postTest setObject:@"APPID" forKey:@"app_id"];
        NSString *userFBID =[NSString stringWithFormat:@"%@",[allInfoDict objectForKey:@"Friends facebook ID "]];

        [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed?access_token=%@",userFBID,[appDelegate.mysession accessToken]]
                                     parameters:postTest
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection,
                                                  NSDictionary * result,
                                                  NSError *error) {
                                  if (error) {

                                      NSLog(@"Error: %@", [error localizedDescription]);

                                  } else {
                                      // Success

                                  }
                              }];

        [postTest release];
于 2013-06-18T08:51:31.707 に答える