将视频上传到Facebook

时间:2011-09-02 05:21:37

标签: android 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);

    }

    }

但是我收到了以下错误消息作为回应 {“error”:{“type”:“OAuthException”,“message”:“(#352)不支持视频文件格式”}}

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

2 个答案:

答案 0 :(得分:1)

请参阅此链接Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

我尝试了在此链接中提到的所有内容,但我得到了与您相同的错误。 然后我清理Facebook参考项目并再次构建它。我的问题解决了。现在视频上传工作..

答案 1 :(得分:0)

您的视频文件有什么奇怪之处吗? WMV应该得到Facebook的支持,但是你可能正在使用一个奇怪的WMV变体,一个受复制保护的变体等等?您是否尝试过与其他视频相同的代码?