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

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

问题描述

我一直在为此工作几天,似乎无法找到一个直接的答案或示例。我正在尝试从我的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:@TestMovieofType:@mp4 ]。 
NSData * data = [NSData dataWithContentsOfFile:filePath];

NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
data,@video,
nil,@callback,
@test,@title ,
@上传测试,@description,
@EVERYONE,@privacy,
nil];

[_facebook requestWithMethodName:@video.upload
andParams:params
andHttpMethod:@POST
andDelegate:self];

由于视频上传电话必须发送到不同的服务器,所以我更改了facebook内的restserver网址.m文件到:

  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:@TestofType:@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的分支中的href =https://github.com/zoul/facebook-ios-sdk/tree/video-upload =nofollow>视频上传分支。我没有碰它几个星期,但它曾经工作正常(只需要旧式认证,请参阅这个分支)。 FBVideoUpload类头文件中有一些注释a>,但界面几乎不言自明。在我的拉动请求下,还有一些有用的讨论 - 特别是关于SSL api-video 集群的证书可以使整个问题更容易,但是我还没有查看代码。



[Rant:很遗憾,iOS SDK的Facebook SDK在GitHub上并没有完全茁壮成长。有很多拉请求,但官方开发人员似乎没有合并任何东西,甚至不是文件中的简单的错字修复。大多数时候拉拉请求只是坐在那里直到被拒绝。]



是的,我提到视频上传代码是一个凌乱的黑客吗?视频上传代码是一个凌乱的黑客。它解析一些认证令牌,并且可能会很快破产,但这是我可以使之工作的唯一方法。






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

  NSData * videoData = [NSData dataWithContentsOfURL:movieURL]; 
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
...,@title,
...,@description,
...,@file,
videoData ,@clip.mov,
nil];
[facebook requestWithGraphPath:@me / videos和Pamams:params和HttpMethod:@POSTandDelegate:self];

这是正确的做法™,以前的解决方案只是一个暂时的黑客。


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];

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.

Any help would be appreciated.

EDIT:

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.

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];  

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];
}

解决方案

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: 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.


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天全站免登陆