2011-09-02 24 views
5

Estoy tratando de subir un video a Facebook usando el siguiente códigoSubir vídeo a Facebook

public void uploadVideosFacebook(String videoPath) 
{ 
    byte[] data = null; 

    String dataMsg = "Your video description here."; 
    String dataName="Mobile.wmv"; 
    Bundle param; 

    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(API); 
    InputStream is = null; 
    try { 
     is = new FileInputStream(videoPath); 
     data = readBytes(is); 

     param = new Bundle(); 
     param.putString("message", dataMsg); 
     param.putString("filename", dataName); 
     param.putByteArray("video", data); 
     mAsyncRunner.request("me/videos", param, "POST", new fbRequestListener(), null); 



    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 



public byte[] readBytes(InputStream inputStream) throws IOException { 
     // this dynamically extends to take the bytes you read 
     ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); 

     // this is storage overwritten on each iteration with bytes 
     int bufferSize = 1024; 
     byte[] buffer = new byte[bufferSize]; 

     // we need to know how may bytes were read to write them to the byteBuffer 
     int len = 0; 
     while ((len = inputStream.read(buffer)) != -1) { 
     byteBuffer.write(buffer, 0, len); 
     } 

     // and then we can return your byte array. 
     return byteBuffer.toByteArray(); 
} 


public class fbRequestListener implements RequestListener { 

    @Override 
    public void onComplete(String response, Object state) { 
     // TODO Auto-generated method stub 
     Log.d("RESPONSE",""+response); 

    } 

    @Override 
    public void onIOException(IOException e, Object state) { 
     // TODO Auto-generated method stub 
     Log.d("RESPONSE",""+e); 

    } 

    @Override 
    public void onFileNotFoundException(FileNotFoundException e, 
      Object state) { 
     // TODO Auto-generated method stub 
     Log.d("RESPONSE",""+e); 

    } 

    @Override 
    public void onMalformedURLException(MalformedURLException e, 
      Object state) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onFacebookError(FacebookError e, Object state) { 
     // TODO Auto-generated method stub 
     Log.d("RESPONSE",""+e); 

    } 

    } 

Pero estoy consiguiendo siguiente mensaje de error en respuesta { "error": { "type": "OAuthException", "mensaje": "(# 352) no se admite el formato de archivo de video"}}

¿Alguien me puede ayudar? Gracias de antemano por tu ayuda.

+0

¿Has visto esto: http://stackoverflow.com/questions/10151708/upload-video-to-facebook-in-android/12470730#12470730 –

Respuesta

0

¿Hay algo extraño en su archivo de video? WMV debe ser compatible con Facebook, pero quizás esté utilizando una variante extraña de WMV, una que esté protegida contra copia, etc. ¿Has probado el mismo código con otro video?

+0

gracias para la respuesta ..... pero ese video se está subiendo a otros sitios como Twitter ... – Vishal

+0

No estoy seguro, entonces. Si definitivamente funciona bien en otro lado, y no hay nada especial sobre el video, puede ser un error en la carga del video por parte de Facebook, tal vez presentar un informe de error detallado y ver si puede ser reproducido. (http://bugs.developers.facebook.net/) – Igy