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 回答