【发布时间】:2016-08-04 13:23:38
【问题描述】:
我正在使用 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 的 suggested method 并且我正在尝试上传工作的 .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 中有一个错误,导致要上传的视频的文件名设置为“源”。
在这里,我们在 GraphRequest.java 的第 2166 和 2167 行看到:
public void writeBytes(String key, byte[] bytes) throws IOException {
writeContentDisposition(key, key, "content/unknown");
和 writeContentDisposition 的参数在同一个文件中的第 2245-2248 行:
public void writeContentDisposition(
String name,
String filename,
String contentType
)
如果是params.putByteArray("source",k);,应该将文件名设置为“源”,没有文件扩展名供 facebook 使用。
添加params.putString("filename", <FILENAME>); 根本不起作用,因为这不会更改错误分配给source 的文件名。
在Graph API 2.5 video reference 我们可以阅读以下内容:
当包含一个源参数时,您应该包含一个带有正确扩展名的文件名,以表明文件容器的类型。
有趣的是,2.6 video reference 中没有这样的内容。
我的问题是:
- GraphRequest.java 中真的存在错误吗?还是 2.6 视频参考正确,文件名不再重要?
- 如果存在错误,当我通过 build.gradle 依赖项使用 API 时如何更改类?
- 如果没有错误,我的上传脚本有什么问题,如何防止 Facebook 给我格式错误响应?
。
【问题讨论】:
标签: android facebook-graph-api video facebook-android-sdk uploading