将视频上传到facebook错误2

时间:2013-06-27 18:43:03

标签: facebook video upload

我正在尝试将使用我的iphone应用程序拍摄的视频上传到Facebook。

在我的应用程序的.plist中,我添加了

FacebookAppId,FacebookDisplayName,URLSchemes和我已经在Facebook开发者处注册了我的应用程序。

在iPhone设置中,我的应用程序可以使用Facebook帐户

然后我允许我的用户为视频标题并给出描述,然后通过点击按钮将其上传到Facebook。

 - (void)buttonRequestClickHandler:(id)sender {

        if (FBSession.activeSession.isOpen) {
  //this is the path to the video          
            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];

//these are the title and description of the video
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错误2) 所以显然我没有从appDelegate开始会话,也没有在这里登录。

 else {
permissions = [NSMutableArray arrayWithObjects:@"publish_actions",@"publish_streams",nil];

  [FBSession openActiveSessionWithPublishPermissions:permissions
  defaultAudience:FBSessionDefaultAudienceOnlyMe
  allowLoginUI:YES
  completionHandler:^(FBSession *session,
  FBSessionState status,
  NSError *error) {
  // if login fails for any reason, we alert THIS IS THE ERROR I GET
  if (error) {
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
    message:error.localizedDescription
    delegate:nil
    cancelButtonTitle:@"OK"
    otherButtonTitles:nil];
    [alert show];




    // if otherwise we check to see if the session is open, an alternative to
    // to the FB_ISSESSIONOPENWITHSTATE helper-macro would be to check the isOpen
    // property of the session object; the macros are useful, however, for more
    // detailed state checking for FBSession objects
    } else if (FB_ISSESSIONOPENWITHSTATE(status)) {
    // send our requests if we successfully logged in

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

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

    NSURL *pathURL = [[NSURL alloc]initFileURLWithPath:fullPatha isDirectory:NO];
    NSData *videoData = [NSData dataWithContentsOfFile:fullPatha];

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

任何人都可以看到我在会话登录时出错了吗?

我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

所以我改变了一些东西。我正在使用HelloFacebookSample应用程序中的代码来确保我已登录并且我不再收到错误2.调试器显示视频开始上传,因为它显示了NSLog for VideoData。然而,过了一段时间,数据流开始显示00000000 00000000 00000000 00000000 00000000 00000000然后可能会有一些像6d766578 00000020一样的东西然后再次以频率增加再次返回零。最后它出错了 2013-06-27 22:50:14.407我的小世界应用程序[8145:907]错误:操作无法完成。 (com.facebook.sdk错误5.) 不确定这意味着什么,但会发布另一个问题。