0

我正在尝试将使用我的 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);}];
                                              }}];
        }}

谁能看到我在登录会话时做错了什么?

我将非常感谢任何人对此的帮助。

4

1 回答 1

0

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

于 2013-06-28T04:55:21.250 回答