【问题标题】:Upload Video to Facebook将视频上传到 Facebook
【发布时间】:2011-09-02 05:21:36
【问题描述】:

我正在尝试使用以下代码将视频上传到 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) 不支持视频文件格式"}}

谁能帮帮我。提前感谢您的帮助。

【问题讨论】:

标签: android facebook


【解决方案1】:

查看此链接Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 感谢您的回复.....但是该视频正在上传到其他网站,例如 twitter...
    • 那么我不确定。如果在其他地方确实可以正常工作,并且视频没有什么特别之处,那可能是Facebook上传视频的错误,也许可以提交详细的错误报告,看看是否可以复制? (bugs.developers.facebook.net)
    猜你喜欢
    • 2011-11-06
    • 2011-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多