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];
}
See Question&Answers more detail:os