【问题标题】:uploading video to Facebook error 5将视频上传到 Facebook 错误 5
【发布时间】:2013-06-28 15:15:26
【问题描述】:

我正在尝试将视频从我的 iPhone 上传到 Facebook。我已经使用 FBLoginView 登录并创建了一个 FBSession。我已经使用以下代码发起了一个上传视频的 FBRequest。

- (void)buttonRequestClickHandler:(id)sender {

if (FBSession.activeSession.isOpen) {

    [FBSession.activeSession requestNewPublishPermissions:permissions
                                    defaultAudience:FBSessionDefaultAudienceOnlyMe
                                        completionHandler:nil];        

    NSString *audioName = [pictureDictionary4 objectForKey:@"photoVideokey"];
    NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectorya = [pathsa objectAtIndex:0];
    NSString *moviePath = [documentsDirectorya stringByAppendingPathComponent:@"/Movie"];
    NSString *fullPatha = [moviePath stringByAppendingPathComponent:audioName];
    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
    NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];

    NSString *titleString = self.videotitle.text;
    NSString *descripString = self.descrp.text;

    NSDictionary *videoObject = @{
                                  @"title":titleString,
                                  @"description": descripString,
                                  [pathURL absoluteString]: videoData
                                  };
    FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
                                                    parameters:videoObject
                                                    HTTPMethod:@"POST"];

   [uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error)
            NSLog(@"Done: %@", result);
        else
            NSLog(@"Error: %@", error.localizedDescription);
    }];
}

我收到一个错误 错误:操作无法完成。 (com.facebook.sdk 错误 5。)

我不确定错误与什么有关:

我知道我已经登录了

我不知道我是否正在连接,但我正在使用 iPhone 上网

我的参数不正确吗? 我已经搞砸了几个小时没有结果 任何人/每个人的任何帮助都将不胜感激。

最后通过进入我的 iPhone 设置-facebook 并删除我的帐户来完成这项工作。然后,当我在我的应用程序中点击上传视频时,它加载了一个视图,询问 Facebook 是否可以使用我的应用程序,我说可以,然后它就上传了。还必须将我的权限更改为仅 publish_actions 并摆脱 publish_streams,因为这是读取权限。无论如何,它现在正在工作。接下来让 defaultAudience 从用户选择的字符串加载,而不是硬编码。另一个帖子。

【问题讨论】:

    标签: facebook facebook-graph-api video file-upload


    【解决方案1】:

    我猜这与流发布许可有关。试试这个方法。它对我有用。我使用的是 Facebook SDK 3.8.0

        [self performPublishAction:^{
    
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"faisal" ofType:@"mov"];
        NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:filePath isDirectory:NO];
        NSData *videoData = [NSData dataWithContentsOfFile:filePath];
    
        NSDictionary *videoObject = @{
                                      @"title": @"This is my title",
                                      @"description": @"This is my description",
                                      [pathURL absoluteString]: videoData
                                      };
        FBRequest *uploadRequest = [FBRequest requestWithGraphPath:@"me/videos"
                                                        parameters:videoObject
                                                        HTTPMethod:@"POST"];
    
        [uploadRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            if (!error)
                NSLog(@"Done: %@", result);
            else
                NSLog(@"Error: %@", error.localizedDescription);
        }];
    }];
    

    - (void) performPublishAction:(void (^)(void)) action {
    if ([FBSession.activeSession.permissions indexOfObject:@"publish_stream"] == NSNotFound) {
        [FBSession.activeSession requestNewPublishPermissions:@[@"publish_stream"]
                                              defaultAudience:FBSessionDefaultAudienceFriends
                                            completionHandler:^(FBSession *session, NSError *error) {
                                                if (!error) {
                                                    action();
                                                } else if (error.fberrorCategory != FBErrorCategoryUserCancelled){
                                                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Permission denied"
                                                                                                        message:@"Unable to get permission to post"
                                                                                                       delegate:nil
                                                                                              cancelButtonTitle:@"OK"
                                                                                              otherButtonTitles:nil];
                                                    [alertView show];
                                                }
                                            }];
    } else {
        action();
    }
    }
    

    【讨论】:

      【解决方案2】:

      此代码已在 FaceBook SDK 3.14.1 上成功测试

      建议: .plist 文件中的 3 个属性

      设置 FacebookAppID、FacebookDisplayName、
      URL types->Item 0->URL Schemes 设置为带有 fb 前缀的 facebookappId See

      -(void)shareOnFaceBook
      {
          //sample_video.mov is the name of file
          NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:@"sample_video" ofType:@"mov"];
      
          NSLog(@"Path  Of Video is %@", filePathOfVideo);
          NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
          //you can use dataWithContentsOfURL if you have a Url of video file
          //NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
          //NSLog(@"data is :%@",videoData);
          NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     videoData, @"video.mov",
                                     @"video/quicktime", @"contentType",
                                     @"Video name ", @"name",
                                     @"description of Video", @"description",
                                     nil];
      
         if (FBSession.activeSession.isOpen)
         {
              [FBRequestConnection startWithGraphPath:@"me/videos"
                                       parameters:params
                                       HTTPMethod:@"POST"
                                completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                    if(!error)
                                    {
                                        NSLog(@"RESULT: %@", result);
                                        [self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
                                    }
                                    else
                                    {
                                        NSLog(@"ERROR: %@", error.localizedDescription);
                                        [self throwAlertWithTitle:@"Denied" message:@"Try Again"];
                                    }
                                }];
          }
          else
          {
              NSArray *permissions = [[NSArray alloc] initWithObjects:
                                  @"publish_actions",
                                  nil];
              // OPEN Session!
              [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone  allowLoginUI:YES
                                           completionHandler:^(FBSession *session,
                                                               FBSessionState status,
                                                               NSError *error) {
                                               if (error)
                                               {
                                                   NSLog(@"Login fail :%@",error);
                                               }
                                               else if (FB_ISSESSIONOPENWITHSTATE(status))
                                               {
                                                   [FBRequestConnection startWithGraphPath:@"me/videos"
                                                                                parameters:params
                                                                                HTTPMethod:@"POST"
                                                                         completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                                                             if(!error)
                                                                             {
                                                                                 [self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
      
                                                                                 NSLog(@"RESULT: %@", result);
                                                                             }
                                                                             else
                                                                             {
                                                                                 [self throwAlertWithTitle:@"Denied" message:@"Try Again"];
      
                                                                                 NSLog(@"ERROR: %@", error.localizedDescription);
                                                                             }
      
                                                                         }];
                                               }
                                           }];
              }
      }
      

      我遇到了错误:

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

      在启动 facebook 时发生。下次我打开我的应用程序时,它运行良好,它总是第一次。尝试了应用程序中的所有内容,但它似乎在 Facebook SDK 方面。

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

      • 会话未打开。验证。
      • Facebook 检测到您正在向系统发送垃圾邮件。更改视频名称。
      • Facebook 对使用 SDK 有明确的限制。尝试其他应用。
      • 错误的发布权限。试一试publish_actions

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-06
        • 2011-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多