iPhone Facebook 视频上传 [英] iPhone Facebook Video Upload

查看:19
本文介绍了iPhone Facebook 视频上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此研究了几天,但似乎无法在任何地方找到直接的答案或示例.我正在尝试从我的 iPhone 应用程序中将视频上传到 Facebook.我可以毫无问题地连接到 facebook(并上传了图片):

I've been working on this for a couple of days now and just can't seem to find a straight answer or example anywhere. I am trying to upload a video to facebook from within my iPhone App. I can connect to facebook (and have uploaded pictures) without a problem using:

_facebook = [[Facebook alloc] initWithAppId:kAppID];
_permissions =  [[NSArray arrayWithObjects:@"publish_stream", @"offline_access",nil] retain];
[_facebook authorize:_permissions delegate:self];

但是我似乎无法让我的视频上传工作.我当前的代码是:

However I can't seem to get my video uploading working. My current code is:

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 更改为:

And since video upload calls have to be made to a different server I changed the restserver url within the facebook.m file to:

static NSString* kRestserverBaseURL = @"https://api-video.facebook.com/method/";

当我运行它时,上传崩溃并出现错误:

When I run this the upload crashes with an error:

facebookErrDomain err 353.

任何帮助将不胜感激.

在 Zoul 的帮助下,我现在实现了以下代码(我没有更改他的上传类及其附带的 SDK 版本).请求不再出错,但没有上传任何内容.

With Zoul's help I now have the following code implemented (I have done nothing to alter his upload class nor the version of the SDK it came with). The request no longer gets an error however nothing is being uploaded.

我初始化了 facebook 对象和上传对象:

I initialize the facebook object and the upload object:

_facebook = [[Facebook alloc] initWithAppId:kAppID];
_permissions =  [NSArray arrayWithObjects:@"publish_stream", @"offline_access",nil];
[_facebook authorize:_permissions delegate:self];
_upload = [[FBVideoUpload alloc] init];  

然后我在 facebook 登录后使用它:

And then I use it once facebook has logged in:

- (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 类头中有一些注释a>,但界面几乎一目了然.在我的 pull request 下也有一些有用的讨论——尤其是关于 SSLapi-video 集群上的证书可以使整个问题更容易,但我还没有审查代码.

I’ve got a video upload branch in my fork of the Facebook SDK on GitHub. I did not touch it for several weeks, but it used to work fine (only it requires the old-style authentication, see this branch). There are some comments in the FBVideoUpload class header, but the interface is pretty much self-explanatory. There’s also some helpful discussion under my pull request – especially the thing about SSL certificates on the api-video cluster that could make the whole issue easier, but I did not review the code yet.

[Rant:遗憾的是,iOS 版 Facebook SDK 并没有完全在 GitHub 上蓬勃发展.有很多拉取请求,但官方开发人员似乎从来没有合并任何东西,甚至没有在文档中进行微不足道的错字修复.大多数情况下,拉取请求只是坐在那里直到被拒绝.]

[Rant: It’s a pity that the Facebook SDK for iOS does not exactly thrive on GitHub. There are many pull requests, but the official developers never seem to merge anything, not even trivial typo fixes in the documentation. Most of the time the pull requests simply sit there until rejected.]

是的,我有没有提到视频上传代码是一个乱七八糟的黑客?视频上传代码是一个凌乱的黑客.它解析了一些身份验证令牌,并且可能很快就会损坏,但这是我当时可以使其正常工作的唯一方法.

And yes, did I mention that the video upload code is a messy hack? The video upload code is a messy hack. It parses some auth tokens and it could break anytime soon, but it was the only way I could make it work back then.

更新:视频上传分支不复存在,您现在可以使用官方SDK轻松上传视频:

Update: The video upload branch is no more, you can now easily upload video using the official 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];

这是正确的方法"™,以前的解决方案只是临时的破解.

This is "the right way to do it"™, the previous solution was just a temporary hack.

这篇关于iPhone Facebook 视频上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆