该操作无法完成。 (com.facebook.sdk错误5.)FACEBOOK视频上传

时间:2013-10-27 11:29:05

标签: ios facebook

我写了以下代码,用于将视频从iOS设备上传到Facebook。

-(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];
                                  }];
    }
}

这给了我错误 无法完成操作。 (com.facebook.sdk错误5。)

我不知道facebook有什么问题。它上传图片,文字,但在视频中它会出现此错误。

注意:

  1. 这不是一次又一次发送,因为我还通过制作新帐户和重置iOS设备进行测试。
  2. sample.mov也存在并与图形api一起使用,但问题在于此SDK。
  3. 感谢。

3 个答案:

答案 0 :(得分:1)

看到com.facebook.sdk错误5:

的原因很少
  • 会话未公开。验证
  • Facebook检测到您正在向系统发送垃圾邮件。更改视频名称。
  • Facebook使用SDK定义了限制。尝试使用其他应用。
  • 错误的发布权限。给publish_actions一个旋转。
  • 更多这里......?

答案 1 :(得分:0)

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

[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);
                                                        }

                                                    }];


    }];

答案 2 :(得分: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
     }
   }];