2011-09-02 103 views
5

我试图将视频上传到Facebook的使用下面的代码视频上传到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); 

    } 

    } 

但我响应 {“错误”收到以下错误消息:{“类型”:“OAuthException” “消息”:“(#352)不支持视频文件格式”}}

任何人都可以帮助我。在此先感谢您的帮助。

+0

你见过这个:http://stackoverflow.com/questions/10151708/upload-video-to-facebook-in-android/12470730#12470730 –

回答

0

你的视频文件有什么奇怪的地方吗? WMV应该得到Facebook的支持,但也许你正在使用WMV的一个奇怪的变体,一个是受版权保护的,等等?你有没有尝试过与另一个视频相同的代码?

+0

谢谢回复.....但该视频正在上传到其他网站,如Twitter ... – Vishal

+0

我不确定,那么。如果它在其他地方一切正常,并且视频没有什么特别之处,它可能是Facebook上的视频上传中的一个错误,可能是提交详细的错误报告,看看它是否可以被复制? (http://bugs.developers.facebook.net/) – Igy