7

I wrote following code for uploading video to facebook from iOS device.

-(void)uploadVideo {

    NSLog(@"UPload Videio ");


    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mov"];

    NSLog(@"Path is %@", filePath);

    NSData *videoData = [NSData dataWithContentsOfFile:filePath];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, @"video.mov",
                                   @"video/quicktime", @"contentType",
                                   @"Video Test Title", @"title",
                                   @"Video Test Description", @"description",
                                   nil];
    //  [facebook requestWithGraphPath:@"me/videos"
    //                         andParams:params
    //                     andHttpMethod:@"POST"
    //                       andDelegate:self];

    if (FBSession.activeSession.isOpen) {


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

                                  if(!error) {
                                      NSLog(@"OK: %@", result);
                                  } else
                                      NSLog(@"Error: %@", error.localizedDescription);

                              }];

    } else {

        // We don't have an active session in this app, so lets open a new
        // facebook session with the appropriate permissions!

        // Firstly, construct a permission array.
        // you can find more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/
        // In this example, we will just request a publish_stream which is required to publish status or photos.

        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"publish_stream",
                                nil];



        //[self controlStatusUsable:NO];
        // OPEN Session!
        [FBSession openActiveSessionWithPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState status,
                                                      NSError *error) {
                                      // if login fails for any reason, we alert
                                      if (error) {

                                          // show error to user.

                                      } else if (FB_ISSESSIONOPENWITHSTATE(status)) {

                                          // no error, so we proceed with requesting user details of current facebook session.


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

                                                                    if(!error) {
                                                                        NSLog(@"VEEERRRRRRR: %@", result);
                                                                    } else
                                                                        NSLog(@"VVEEERRRRREEEERRR: %@", error.localizedDescription);

                                                                }];





                                          //[self promptUserWithAccountNameForUploadPhoto];
                                      }
                                      // [self controlStatusUsable:YES];
                                  }];
    }
}

This gives me error The operation couldn’t be completed. (com.facebook.sdk error 5.)

I don't know what is wrong with facebook. It uploads image, text, but in video it gives this error.

NOTE:

  1. It is not due to send again and again, as I also tested by making new account and resetting iOS Device.
  2. sample.mov also exists and works with graph api, but issue is with this SDK.

Thanks.

4

3 回答 3

1

看到 com.facebook.sdk 错误 5 的几个原因:

  • 会话未打开。证实。
  • Facebook 检测到您正在向系统发送垃圾邮件。更改视频名称。
  • Facebook 使用 SDK 有明确的限制。尝试不同的应用程序。
  • 错误的发布权限。给 publish_actions 一个旋转。
  • 更多这里...?
于 2014-01-10T18:30:11.433 回答
0

已阅读解决方案。我能够解决这个问题。

[FBRequestConnection startWithGraphPath:@"me/videos"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result, NSError *error)
    {
       [FBRequestConnection startWithGraphPath:@"me/videos"
                                    parameters:params
                                    HTTPMethod:@"POST"
                             completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                                        if(!error)
                                                        {
                                                            NSLog(@"SUCCESS RESULT: %@", result);
                                                        }
                                                        else
                                                        {
                                                            NSLog(@"ERROR: %@", error.localizedDescription);
                                                        }

                                                    }];


    }];
于 2015-01-23T07:41:50.893 回答
0

当我注意到我的应用程序没有出现在以下位置时,我整天都遇到这个问题:

设置应用程序->Facebook->“允许这些应用程序使用您的帐户”

这让我意识到默认情况下不允许发布到 Facebook,您必须提示用户许可:

 [[FBSession activeSession] requestNewPublishPermissions:@[@"publish_actions"]
                                         defaultAudience:FBSessionDefaultAudienceFriends
                                       completionHandler:^(FBSession *session, NSError *error)
   {
     if (!error)
     {
        // UPLOAD VIDEO HERE AND THAT ERROR 5 SHOULD GO AWAY
     }
   }];
于 2015-05-27T01:42:25.370 回答