在Facebook上发布多张带有状态信息的照片

时间:2013-11-16 08:04:01

标签: ios facebook image facebook-graph-api

我在发布此图片时遇到问题。所有图片的常用标题&多个图像。至少,告诉我它是否可能

enter image description here

我试图遍历所有图像&成功发布图像中显示的所有图像,但没有获得标题。 (在图像中:“测试:请不要忘了。”)。我该怎么办?

我的代码发布成功,但问题是每张照片都是不同的帖子。我希望所有照片都在一个帖子中。

这是我试过的:

    NSMutableArray *arrayOfImages = [self getSelectedImagesArray];
    for (int i=0; i<arrayOfImages.count; i++)
    {
        NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
        [params setObject:@"LOL !! THIS IS IMAGE" forKey:@"message"];
        //[params setObject:@"LOL !! APP NAME" forKey:@"name"];
        [params setObject:@"LOL !! THIS IS IMAGE CAPTION" forKey:@"caption"];
        [params setObject:@"LOL !! THIS IS IMAGE description" forKey:@"description"];
        [params setObject:UIImageJPEGRepresentation([arrayOfImages objectAtIndex:i], 0.5) forKey:@"picture"];

        [FBRequestConnection startWithGraphPath:@"me/photos"
                                     parameters:params
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection,
                                                  id result,
                                                  NSError *error)
         {
             NSString *alertText;

             if (error)
             {
                 //showing an alert for failure
                 [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
                  {
                      [self shareAdvertOnFacebook];
                  }];
                 alertText = [NSString stringWithFormat: @"error: domain = %@, code = %d", error.domain, error.code];
             }
             else
             {
                 //showing an alert for success
                 alertText = [NSString stringWithFormat: @"Posted action, id: %@", result[@"id"]];
                 [[[UIAlertView alloc] initWithTitle:@"Result" message:@"Advert is posted to Facebook successfully." delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil] show];
             }
         }];
    }

1 个答案:

答案 0 :(得分:2)

首先确保您拥有publish_stream权限才能创建新相册。 然后,要创建新相册,请使用访问令牌,相册名称和相册说明的参数对https://graph.facebook.com/me/albums进行Graph API调用。

如果成功创建了相册,则会返回新的相册ID。 然后使用访问令牌和其他照片参数拨打https://graph.facebook.com/NEW_ALBUM_ID/photos,将您的照片上传到新相册。

默认情况下,如果您没有指定任何相册,只是将照片推送到我/照片端点,那么您的照片最终将会自动为您的应用创建相册。

此代码对我有用,只需将代码添加到“发布所有图片”

- (void) postImageToFB:(UIImage*)image
    {
        NSData* imageData = UIImageJPEGRepresentation(image, 90);
        NSString *text=@"Purchased a book From Library Store,\nBook Name-";
        text=[text stringByAppendingString:lbl_bk_name.text];
        text=[text stringByAppendingString:@"\nCategory-"];
        text=[text stringByAppendingString:lbl_bk_category.text];
        text=[text stringByAppendingString:@"\nFeeling Great!!"];


        NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                        text, @"message",
                                        imageData, @"source",
                                        nil];

        [FBRequestConnection startWithGraphPath:@"me/photos"
                                     parameters:params
                                     HTTPMethod:@"POST"
                              completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {


                                  if (error) {
                                      UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Problem in sharing in Facebook. Try Later!" delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];
                                      [alert show];
                                  } else {


                                          UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Shared Successfully." delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];
                                          [alert show];

                                  }



                              }];
    }