android - 上传视频到 Facebook

标签 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) 不支持视频文件格式"}}

谁能帮帮我。预先感谢您的帮助。

最佳答案

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

我尝试了此链接中提到的所有内容,但遇到了与您相同的错误。 然后我清理 Facebook 引用项目并重新构建它。我的问题已经解决了。现在可以上传视频了。

关于android - 上传视频到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7279510/

相关文章:

java - contentResolver 返回 null

php - 使用 cURL PHP/Graph API 在 Facebook 中发布对评论的回复

Facebook 分享按钮 - 自定义图像

java - 在删除项目后更新 StableIdKeyProvider 缓存和 RecyclerView/SelectionTracker 在新选择时崩溃

android - 自定义可见性转换器 - Android - 发布 (MvvmCross)

android - 以编程方式在 TableLayout 中添加行的问题

android - 库项目中的 Res 文件夹

ios - 无法使用 Swift Decodable 解析 JSON

facebook - 如何通过 Facebook 的 Graph API 获取共同好友

Facebook 登录 - 如何在本地主机和生产环境中进行开发?