简体   繁体   English

尝试使用iPhone的FBConnect将视频上传到Facebook

[英]Trying to upload video to facebook using FBConnect for iPhone

I am working on an app which will upload videos to a Facebook users wall, however I have not had much success. 我正在开发一个将视频上传到Facebook用户墙的应用程序,但是我没有取得太大的成功。 I present an extended permissions dialog window, and then use the face.video.upload method call. 我展示了一个扩展的权限对话框窗口,然后使用face.video.upload方法调用。 In the debugger, it seems like each parameter is set correctly, however the ext permission dialog never completely displays, and the video file never uploads. 在调试器中,似乎每个参数都设置正确,但是ext权限对话框永远不会完全显示,视频文件也永远不会上传。

The video file is stored in the app's documents directory (record and playback work fine) but the upload is broken. 视频文件存储在应用程序的文档目录中(录制和播放正常),但上传中断。 I have the video.upload parameters in the dialogDidSucceed: method, and I have modified the FBRequest.m generatePostBody: method to accept video files. 我在dialogDidSucceed:方法中具有video.upload参数,并且我修改了FBRequest.m generatePostBody:方法以接受视频文件。

Any help would be tremendous, as I have been banging my head against the wall on this one. 任何帮助都是巨大的,因为我一直在用力撞墙。 Thanks in advance. 提前致谢。

Here is the view controller code: 这是视图控制器代码:

-(IBAction)loginToFacebook
{
  session = [[FBSession sessionForApplication:kAPIKey secret:kAPISecret delegate:self] retain];

  FBLoginDialog *loginDialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];

  [loginDialog show];
}

-(IBAction)askPermission
{
  //---------------ask permission---------------------/
  FBPermissionDialog *permDialog = [[[FBPermissionDialog alloc]init]autorelease];

  permDialog.delegate = self;

  permDialog.permission = @"video_upload";

  [permDialog show];
}   


-(void)dialogDidSucceed:(FBPermissionDialog *)dialog
{

  //---------------video file path--------------------/
  NSString *path = [NSString stringWithFormat:@"%@/Documents/%@.mov", NSHomeDirectory(), aSelectedQuote.quoteID];

  //---------------video data converter---------------/

  NSData *videoData = [NSData dataWithContentsOfFile:path];

  videoFileName = [NSString stringWithUTF8String:[videoData bytes]];

  //---------------dict for FB upload-----------------/
  NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];

  [args setObject:videoFileName forKey:@"video"];
  [args setObject:aSelectedQuote.quoteTitle forKey:@"title"];

  //---------------FBRequest--------------------------/
  FBRequest *uploadVideoRequest = [FBRequest requestWithDelegate:self];

  [uploadVideoRequest call:@"facebook.video.upload" params:args dataParam:videoData];

  //[uploadVideoRequest call:@"facebook.video.upload" params:args];


  NSLog(@"Upload video button pushed.");

}

-(void)dialogDidCancel:(FBDialog *)dialog
{
  NSLog(@"user canceled request");
}



-(void)session:(FBSession *)session didLogin:(FBUID)uid
{
  NSLog(@"user with id %lld logged in.",uid);

  NSString *fql = [NSString stringWithFormat:@"select uid, name from user where uid == %lld", session.uid];

  NSDictionary *params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];

  [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];

}

/*
  -(void)sessionDidLogout:(FBSession *)session
  {
  }
*/


-(void)request:(FBRequest *)request didLoad:(id)result
{
  if ([result isKindOfClass:[NSArray class]])
    {
      NSArray *users = result;
      NSDictionary *user = [users objectAtIndex:0];
      NSString *name = [user objectForKey:@"name"];

      NSLog(@"FBRequest didLoad: - logged in as %@",name);
    }
}

-(void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error
{
  NSLog(@"Error (%d) %@", [error code], [error localizedDescription]);
}

Here is the FBRequest.m code: 这是FBRequest.m代码:

- (NSMutableData*)generatePostBody {
  NSMutableData* body = [NSMutableData data];
  NSString* endLine = [NSString stringWithFormat:@"\r\n--%@\r\n", kStringBoundary];

  [self utfAppendBody:body data:[NSString stringWithFormat:@"--%@\r\n", kStringBoundary]];

  for (id key in [_params keyEnumerator]) {
    [self utfAppendBody:body
      data:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]];
    [self utfAppendBody:body data:[_params valueForKey:key]];
    [self utfAppendBody:body data:endLine];
  }

  if (_dataParam != nil) {
    if ([_dataParam isKindOfClass:[UIImage class]]) {
      NSData* imageData = UIImagePNGRepresentation((UIImage*)_dataParam);
      [self utfAppendBody:body
        data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"photo\"\r\n"]];
      [self utfAppendBody:body
        data:[NSString stringWithString:@"Content-Type: image/png\r\n\r\n"]];
      [body appendData:imageData];
    } else {
      NSAssert([_dataParam isKindOfClass:[NSData class]], @"dataParam must be a UIImage or NSData");
      /*           
               [self utfAppendBody:body
               data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data\"\r\n"]];
               [self utfAppendBody:body
               data:[NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"]];
               [body appendData:(NSData*)_dataParam];
      */
      if ([_method isEqualToString:@"facebook.video.upload"]) {
    [self utfAppendBody:body
          data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data.mov\"\r\n"]];
    [self utfAppendBody:body
          data:[NSString stringWithString:@"Content-Type: video/quicktime\r\n\r\n"]];
      }
      else {
    [self utfAppendBody:body
          data:[NSString stringWithFormat:@"Content-Disposition: form-data; filename=\"data\"\r\n"]];
    [self utfAppendBody:body
          data:[NSString stringWithString:@"Content-Type: content/unknown\r\n\r\n"]];
      }

    }
    [self utfAppendBody:body data:endLine];
  }

  FBLOG2(@"Sending %s", [body bytes]);
  return body;
}

You're setting videoFileName to the raw bytes of the videofile: 您正在将videoFileName设置为视频文件的原始字节:

videoFileName = [NSString stringWithUTF8String:[videoData bytes]];
....
[args setObject:videoFileName forKey:@"video"];

I think you meant: 我想你的意思是:

videoFileName = [path lastPathComponent];

I hope this fixes your problem. 我希望这可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM