¿Cómo compartir video en Facebook SDK?

Escribí el código como a continuación donde existe el file en resources. No es nulo

Tengo éxito en agregar imágenes, pero atrapado en videos.

-(void)uploadVideo { NSLog(@"UPload Videio "); NSString *filePath = [[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]; NSError *error = nil; NSData *data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error:&error]; if(data == nil && error!=nil) { //Print error description NSLog(@"error is %@", [error description]); } NSLog(@"data is %@", data); NSDictionary *parameters = [NSDictionary dictionaryWithObject:data forKey:@"sample.mov"]; if (FBSession.activeSession.isOpen) { [FBRequestConnection startWithGraphPath:@"me/videos" parameters:parameters HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { // [FBRequestConnection setVideoMode:NO]; if(!error) { NSLog(@"OK: %@", result); } else NSLog(@"Error: %@", error.localizedDescription); }]; } else { // We don't have an active session in this app, so lets open a new // facebook session with the appropriate permissions! // Firstly, construct a permission array. // you can find more "permissions strings" at http://developers.facebook.com/docs/authentication/permissions/ // In this example, we will just request a publish_stream which is requinetworking to publish status or photos. NSArray *permissions = [[NSArray alloc] initWithObjects: @"publish_stream", nil]; //[self controlStatusUsable:NO]; // OPEN Session! [FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { // if login fails for any reason, we alert if (error) { // show error to user. } else if (FB_ISSESSIONOPENWITHSTATE(status)) { // no error, so we proceed with requesting user details of current facebook session. [FBRequestConnection startWithGraphPath:@"me/videos" parameters:parameters HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { // [FBRequestConnection setVideoMode:NO]; if(!error) { NSLog(@"Result: %@", result); } else NSLog(@"ERROR: %@", error.localizedDescription); }]; //[self promptUserWithAccountNameForUploadPhoto]; } // [self controlStatusUsable:YES]; }]; } } 

A cambio, recibo un error como

 The operation couldn't be completed. (com.facebook.sdk error 5.) 

¿Cómo upload video a Facebook usando facebook iOS SDK?

Gracias

Aquí hay un método para upload videos a Facebook. Este código está probando y funcionando al 100%.

 ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; // Specify App ID and permissions NSDictionary *options = @{ACFacebookAppIdKey: FACEBOOK_ID, ACFacebookPermissionsKey: @[@"publish_stream", @"video_upload"], ACFacebookAudienceKey: ACFacebookAudienceFriends}; // basic read permissions [accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *e) { if (granted) { NSArray *accountsArray = [accountStore accountsWithAccountType:facebookAccountType]; if ([accountsArray count] > 0) { ACAccount *facebookAccount = [accountsArray objectAtIndex:0]; NSDictionary *parameters = @{@"description": aMessage}; SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://graph.facebook.com/me/videos"] parameters:parameters]; [facebookRequest addMultipartData: aVideo withName:@"source" type:@"video/mp4" filename:@"video.mov"]; facebookRequest.account = facebookAccount; [facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) { if (error == nil) { NSLog(@"responedata:%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]); }else{ NSLog(@"%@",error.description); } }]; } } else { NSLog(@"Access Denied"); NSLog(@"[%@]",[e localizedDescription]); } }]; 

Recomendación:

Creo que esto podría ser un problema de permissions, pero no estoy seguro de dónde se está produciendo el error. El método de delegado que se lanzaría no se muestra en su código. Creo que reconciliar su código con los pasos de esta muestra puede ser útil; Si es así, por favor acepte la respuesta.

Algunos aspectos key de la muestra:

Permisos:

 - (IBAction)buttonClicked:(id)sender { NSArray* permissions = [[NSArray alloc] initWithObjects: @"publish_stream", nil]; [facebook authorize:permissions delegate:self]; [permissions release]; } 

Solicitud de construcción:

 - (void)fbDidLogin { NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" 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]; } 

Solicitar el método didLoad delegate:

 - (void)request:(FBRequest *)request didLoad:(id)result { if ([result isKindOfClass:[NSArray class]]) { result = [result objectAtIndex:0]; } NSLog(@"Result of API call: %@", result); } 

Solicitar el método de delegado didFail:

 - (void)request:(FBRequest *)request didFailWithError:(NSError *)error { NSLog(@"Failed with error: %@", [error localizedDescription]); } 

Enlace de permissions de video de Facebook

Este código se testing con éxito en FaceBook SDK 3.14.1

Recomendación: en .plist

establezca FacebookAppID, FacebookDisplayName,
Tipos de URL-> Artículo 0-> Esquemas de URL configurados en el prefijo facebookappId con fb

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

Y tengo un error:

  The operation couldn't be completed. (com.facebook.sdk error 5.) 

Ocurre cuando se está iniciando Facebook. La próxima vez que abro mi aplicación, funciona bien, siempre es la primera vez. Intenté todo en la aplicación, pero parece estar en el lado SDK de Facebook.

Pocas causas para ver com.facebook.sdk error 5 :

  • La session no está abierta. Validar.
  • Facebook ha detectado que está enviando spam al sistema. Cambia el nombre del video.
  • Facebook tiene un límite definido utilizando el SDK. Prueba una aplicación diferente.

¿Solicitaste un permiso de publish_stream antes?