如何使用FBConncet在Facebook上传视频?

时间:2012-12-10 11:07:26

标签: iphone xcode url video fbconnect

在我的应用程序中我试图在Facebook墙上使用FbConnect上传视频我的代码看起来很好但我不知道为什么我的视频没有上传如果我使用相同的代码方法上传图像它成功上传图像facebook.here是我用于图片上传的代码

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfFile:filePath];
UIImage *img  = [[UIImage alloc] initWithData:data];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                             img, @"Picture",
                             nil];
[_facebook requestWithGraphPath:@"me/photos"
                    andParams:params
                    andHttpMethod:@"POST"
                    andDelegate:self];
[img release];

对于视频,我正在尝试此代码,以便

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];
 NSURL *url = [NSURL URLWithString:filePath];
 NSData *videoData = [NSData dataWithContentsOfURL:url];
 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               videoData, @"video.mp4",
                               @"video/quicktime", @"contentType",
                               @"Video Test Title", @"title",
                               @"Video Test Description", @"description",
                               nil];
[_facebook requestWithGraphPath:@"me/videos"
                     andParams:params
                 andHttpMethod:@"POST"
                   andDelegate:self];

上面的代码没有给我任何错误,但它在标签中重新调整了一些文本消息(操作无法完成)。哪些不是图像上传。所以可以指导我如何修复它。谢谢

2 个答案:

答案 0 :(得分:5)

尝试以下几行:

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];
      NSData *videoData = [NSData dataWithContentsOfFile:filePath];
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   videoData, @"video.mp4",
                                   @"video/quicktime", @"contentType",
                                   @"Video Test Title", @"title",
                                   @"Video Test Description", @"description",
                                   nil];
    [_facebook requestWithGraphPath:@"me/videos"
                         andParams:params
                     andHttpMethod:@"POST"
                       andDelegate:self];

希望这能帮助你。对我来说工作正常。现在添加这些行。

答案 1 :(得分:3)

 http://stackoverflow.com/questions/10509984/how-to-upload-mp4-video-on-facebook-using-graph-api-in-objective-c

http://%5B1%5D:%20https://github.com/reallylongaddress/iPhone-Facebook-Graph-API

http://stackoverflow.com/questions/12861615/upload-video-to-facebook-using-facebook-new-sdk-on-ios-6-0