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];
}
If the Facebook app will not let you upload video, you may have a problem with your phone's privacy settings. Other reasons for faulty uploads include uploading videos in a unsupported file type or Web browser, which can cause many problems, including extended encoding and processing wait times.
To ensure your upload is of the highest quality make sure in the settings of Facebook, under Video Settings, "Upload HD" is selected. Steps for this are here. Check to make sure that in your iOS Facebook settings, you have "Upload HD" turned on (it is off by default).
If your Facebook video is not uploading, there is a good chance that either your video is too long, is larger than the limit, or it simply does not have the correct video format that Facebook uses. As mentioned previously, make sure that your video is compatible before uploading to save time and stress.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With