通过Android上的Graph API上载视频时出错

通过Android上的Graph API上载视频时出错,android,facebook-graph-api,video,facebook-android-sdk,uploading,Android,Facebook Graph Api,Video,Facebook Android Sdk,Uploading,我正在使用Graph API开发概念验证Android应用程序。我正在尝试将视频上传到我的Facebook应用程序的相册中 我使用这部分代码来执行此操作: String dataName = new File(getRealPathFromURI(this,data.getData())).getName(); Toast.makeText(this,dataName,Toast.LENGTH_LONG).show(); params.putStr

我正在使用Graph API开发概念验证Android应用程序。我正在尝试将视频上传到我的Facebook应用程序的相册中

我使用这部分代码来执行此操作:

String dataName = new File(getRealPathFromURI(this,data.getData())).getName();
            Toast.makeText(this,dataName,Toast.LENGTH_LONG).show();
            params.putString("filename", new File(getRealPathFromURI(this,data.getData())).getName());
            params.putByteArray("source",k);
            /* make the API call */
            new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/"+sProfile.getId()+"/videos",
                    params,
                    HttpMethod.POST,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
                            TextView textView = (TextView) findViewById(R.id.textView2);
                                textView.setText(response.toString()+" "+k.length);
                            Log.v("Response:",response.toString());
                        }
                    }
            ).executeAsync();
尽管这是Android版,相当于Facebook版,而且我正试图上传工作的
.mp4
文件,但我得到了这个错误

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400,errorCode: 352, errorType: OAuthException, errorMessage: Sorry, the video file you selected is in a format that we don't support.}}
在我看来,Android Facebook SDK中的GraphRequest.java中存在一个bug,导致上传的视频文件名仅设置为“source”

在GraphRequest.java的第2166行和第2167行中,我们看到:

public void writeBytes(String key, byte[] bytes) throws IOException {
        writeContentDisposition(key, key, "content/unknown");
以及同一文件中第2245-2248行的writeContentDisposition的参数:

public void writeContentDisposition(
            String name,
            String filename,
            String contentType
    )
参数putByteArray(“源”,k)的情况下,应为:将文件名设置为“source”,没有可供facebook使用的文件扩展名

添加
params.putString(“文件名”)根本不起作用,因为这不会改变错误分配给
源代码的文件名

在本文中,我们可以阅读以下内容:

在包含源参数时,应包含具有正确扩展名的文件名,该扩展名指示文件容器的类型

有趣的是,里面没有这样的文字

我的问题是:

  • GraphRequest.java中真的有bug吗?或者2.6视频参考是否正确,文件名是否不再重要
  • 如果存在bug,当我通过build.gradle依赖项使用API时,如何更改类
  • 如果没有bug,我的上传脚本有什么问题,如何防止Facebook给我格式错误响应

  • 所以,Facebook Android SDK中似乎真的存在漏洞

    作为一种变通方法,我使用了,并使用它创建了以下方法:

    void uploadVideo(String name, InputStream is, String fileName){
        AsyncHttpClient client = new AsyncHttpClient();
        RequestParams rp = new RequestParams();
        rp.put("access_token",AccessToken.getCurrentAccessToken().getToken());
        rp.put("name",name);
        rp.put("source",is,fileName);
        client.post(this, "https://graph-video.facebook.com/me/videos", rp, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                //something...
            }
    
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                //something...
            }
        });
    }
    
    一切都按计划进行