[英]iPhone Facebook Video Upload
我已经在这方面工作了几天,似乎无法在任何地方找到直接的答案或例子。 我正试图从我的iPhone应用程序中将视频上传到Facebook。 我可以连接到Facebook(并上传图片)没有问题使用:
_facebook = [[Facebook alloc] initWithAppId:kAppID];
_permissions = [[NSArray arrayWithObjects:@"publish_stream", @"offline_access",nil] retain];
[_facebook authorize:_permissions delegate:self];
但是我似乎无法让我的视频上传工作。 我目前的代码是:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TestMovie" ofType:@"mp4"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
data, @"video",
nil, @"callback",
@"test", @"title",
@"upload testing", @"description",
@"EVERYONE", @"privacy",
nil];
[_facebook requestWithMethodName:@"video.upload"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
由于必须将视频上传调用发送到不同的服务器,我将facebook.m文件中的restserver url更改为:
static NSString* kRestserverBaseURL = @"https://api-video.facebook.com/method/";
当我运行这个时,上传崩溃并出现错误:
facebookErrDomain err 353.
任何帮助,将不胜感激。
编辑:
在Zoul的帮助下,我现在实现了以下代码(我没有做任何改变他的上传类和它附带的SDK的版本)。 请求不再出错,但是没有上传任何内容。
我初始化facebook对象和上传对象:
_facebook = [[Facebook alloc] initWithAppId:kAppID];
_permissions = [NSArray arrayWithObjects:@"publish_stream", @"offline_access",nil];
[_facebook authorize:_permissions delegate:self];
_upload = [[FBVideoUpload alloc] init];
一旦facebook登录,我就会使用它:
- (void)fbDidLogin{
_upload.accessToken = _facebook.accessToken;
_upload.apiKey = kApiKey;
_upload.appSecret = kApiSecret;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Test" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
data, @"",
@"test", @"title",
@"upload testing", @"description",
@"EVERYONE", @"privacy",
nil];
[_upload startUploadWithURL:fileURL params:params delegate:self];
}
我在GitHub上的Facebook SDK的分支中有一个视频上传分支 。 我好几周都没有触摸它,但它曾经工作正常(只需要旧式身份验证,请参阅此分支 )。 FBVideoUpload类头中有一些注释,但界面几乎是不言自明的。 在我的拉取请求下还有一些有用的讨论 - 尤其是关于api-video
集群上的SSL证书可以使整个问题更容易,但我还没有查看代码。
[Rant:很遗憾,Facebook SDK for iOS并没有完全在GitHub上茁壮成长。 有许多拉取请求,但官方开发人员似乎永远不会合并任何东西,甚至文档中甚至没有琐碎的拼写错误修复。 大部分时间拉动请求只是坐在那里直到被拒绝。
是的,我是否提到视频上传代码是一个混乱的黑客? 视频上传代码是一个混乱的黑客。 它解析了一些auth令牌,它可能很快就会崩溃,但这是我能让它恢复正常工作的唯一方法。
更新:视频上传分支已不复存在,您现在可以使用官方SDK轻松上传视频:
NSData *videoData = [NSData dataWithContentsOfURL:movieURL];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
…, @"title",
…, @"description",
…, @"file",
videoData, @"clip.mov",
nil];
[facebook requestWithGraphPath:@"me/videos" andParams:params andHttpMethod:@"POST" andDelegate:self];
这是“正确的方法”,以前的解决方案只是暂时的黑客攻击。
- (void)viewDidLoad
{
facebook = [[Facebook alloc] initWithAppId:@"276907032339239"];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)buttonClicked:(id)sender
{
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"publish_stream", nil];
[facebook authorize:permissions delegate:self];
[permissions release];
}
- (void)fbDidLogin
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/videos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
NSLog(@"hiiiiiiiii");
}
-(void)fbDidNotLogin:(BOOL)cancelled
{
NSLog(@"did not login");
}
- (void)request:(FBRequest *)request didLoad:(id)result
{
if ([result isKindOfClass:[NSArray class]])
{
result = [result objectAtIndex:0];
}
NSLog(@"Result of API call: %@", result);
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed with error: %@", [error localizedDescription]);
}
您可以使用新的图表API来上传视频:
你可以使用这个fork https://github.com/johnmph/facebook-ios-sdk并有一个这样的param字典:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:movieData, @"source", @"File.mov", @"filename", nil];
[m_facebook requestWithGraphPath:@"me/videos" andParams:params andHttpMethod:@"POST" andDelegate:self];
我还在这个fork中添加了一个跟踪上传状态的方法(例如用于进度条)
您是否尝试将其发送到电子邮件,因为Facebook浏览了http://www.facebook.com/help/?faq=12345您可以使用电子邮件主题设置视频的标题。
实际上,值得一提的是要关注Facebook的各种工程博客。 这个日期是2011年10月,因此没有“当前”SDK: http : //developers.facebook.com/blog/post/532/
但是,如果您修改捆绑包ID,将URL方案添加到plist,并将自己的App ID添加到视图控制器,则示例仍然有效:
这是我在视频上传时发现的最有用的信息 - 我不知道为什么Facebook会将其与主要的SDK文档混为一谈! 奇怪的是,没有任何关联,我不得不做一些挖掘......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.