Reputation: 2087
I am trying to upload video from the iPhone application using FBConnect. Actually I have tried several ways but unfortunately without any success.
First. Using "facebook.video.upload" REST method and tricks described here iPhone Facebook Video Upload. As a result server returns an empty response and anything more happens afterwards. Video doesn't appear on facebook. Have tried different types of facebook apps by the way, such as WebApp and Native one.
Second. Using "me/videos" GRAPH method and below code to initiate uploading
>
NSMutableDictionary *params = [NSMutableDictionary
dictionaryWithObjectsAndKeys:movieData,
@"source", @"File.mov", @"filename",
nil];
[m_facebook requestWithGraphPath:@"me/videos"
andParams:params andHttpMethod:@"POST" andDelegate:self];
In such a case I'm getting the next errors:
a) An active access token must be used to query information about the current user.
b) Video file format is not supported.
Third. Simply send an email with video file attached to [email protected]. Doesn't work. However this solution is not so interested as previous are.
I have spent 2 days figuring those things out and it makes me crazy. Could someone please share a working example of video uploading or at least point me out where I am wrong in my samples.
Thank you!
Upvotes: 4
Views: 3390
Reputation: 1123
This Code is Tested successfully On FaceBook SDK 3.14.1
Recommendation: 3 properties in .plist file
set FacebookAppID,FacebookDisplayName,
URL types->Item 0->URL Schemes set to facebookappId prefix with fb
See
-(void)shareOnFaceBook
{
//sample_video.mov is the name of file
NSString *filePathOfVideo = [[NSBundle mainBundle] pathForResource:@"sample_video" ofType:@"mov"];
NSLog(@"Path Of Video is %@", filePathOfVideo);
NSData *videoData = [NSData dataWithContentsOfFile:filePathOfVideo];
//you can use dataWithContentsOfURL if you have a Url of video file
//NSData *videoData = [NSData dataWithContentsOfURL:shareURL];
//NSLog(@"data is :%@",videoData);
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video name ", @"name",
@"description of Video", @"description",
nil];
if (FBSession.activeSession.isOpen)
{
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(@"RESULT: %@", result);
[self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
}
else
{
NSLog(@"ERROR: %@", error.localizedDescription);
[self throwAlertWithTitle:@"Denied" message:@"Try Again"];
}
}];
}
else
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_actions",
nil];
// OPEN Session!
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (error)
{
NSLog(@"Login fail :%@",error);
}
else if (FB_ISSESSIONOPENWITHSTATE(status))
{
[FBRequestConnection startWithGraphPath:@"me/videos"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
[self throwAlertWithTitle:@"Success" message:@"Video uploaded"];
NSLog(@"RESULT: %@", result);
}
else
{
[self throwAlertWithTitle:@"Denied" message:@"Try Again"];
NSLog(@"ERROR: %@", error.localizedDescription);
}
}];
}
}];
}
}
And I GOT Error When app Is Run First time:
The operation couldn’t be completed. (com.facebook.sdk error 5.)
It happens when facebook is being inited. Next time i open my app, it works fine, its always the first time. Tried everything in app, but it seems to be on the Facebook SDK side.
Few causes for seeing com.facebook.sdk error 5
:
publish_actions
a spin.Upvotes: 0
Reputation: 21
They are little old, but still working fine. http://developers.facebook.com/attachment/VideoUploadTest.zip Maybe this source will help to someone. But don't forget to change AppID to your. I've made it in 3 places
facebook = [[Facebook alloc] initWithAppId:@"..."]; and 2 properties in plist file - FacebookAppID, URL types array https://i.sstatic.net/yZAXQ.png
- (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:@"buf-3" 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];
}
Good luck!
Upvotes: 0
Reputation: 11
NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
NSString *urlString=[urlvideo path];
NSLog(@"urlString=%@",urlString);
NSString *str = [NSString stringWithFormat:@"you url of server"];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setFile:urlString forKey:@"key foruploadingFile"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startSynchronous];
NSLog(@"responseStatusCode %i",[request responseStatusCode]);
NSLog(@"responseStatusCode %@",[request responseString]);
Upvotes: 1
Reputation:
You should use the Graph method, since the old API is deprecated and will go away at some point in the fairly near future. Therefore, I'll address that.
The first problem is that you can't just upload a video to Facebook without being logged in somehow. You'll need to follow these instructions to get an access token before you can upload videos: http://developers.facebook.com/docs/authentication
You'll also need the upload_video
permission, which for some reason isn't listed on the "Permissions" page.
I'm not sure about the second issue, but Facebook supports a number of video formats. Presumably your video is in one of the Apple formats, which are probably supported. Fix the first issue, and see if that has any effect on the second one.
Upvotes: 3