{
Request request = null;
RequestAsyncTask task = null ;
Bundle requestParams requestParams=new Bundle();
byte[] data = downloadUrl(new URL("urltodownload"));
requestParams.putByteArray("video", data);
requestParams.putString("title", "Video post");
requestParams.putString("description", " #SomeTag");
request = new Request(Session.getActiveSession(),"me/videos" , requestParams,
HttpMethod.POST,new Request.Callback() {
@Override
public void onCompleted(Response response) {
//appLink=null;
if (response.getError() == null) {
Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish success");
if (uploadListener != null) {
uploadListener.onSuccess(null);
}
} else {
Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish error: "
+ response.getError().getErrorMessage());
Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish error: "
+ response.getError().toString());
if (uploadListener != null) {
uploadListener
.onError("Facebook can't publish your content");
}
}
}
});
task = new RequestAsyncTask(request);
task.execute();
}
private static byte[] downloadUrl(URL toDownload) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
byte[] chunk = new byte[4096];
int bytesRead;
InputStream stream = toDownload.openStream();
while ((bytesRead = stream.read(chunk)) > 0) {
outputStream.write(chunk, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
return outputStream.toByteArray();
}
我不知道我做错了什么,但每次我得到这个错误。还有其他的方法来发布视频到facebook墙吗?我知道怎么上传视频newUploadVideoRequest方法,但在我的情况下,我不想下载视频并将其保存到sd卡,然后发布到facebook。还有其他的方式,我可以调用图形api url和张贴视频到facebook墙,但是否有其他方法可以让我直接将视频发布到facebook墙上,我几乎引用了每个链接{HttpStatus: 500, errorCode: 352, errorType: FacebookApiException,errorMessage:对不起,您选择的视频文件的格式为不支持。}
我只是改变
requestParams。 . putByteArray("video", data) requestParams.putByteArray("视频。3 gp"数据),
它上传成功了你可以试试。mp4也很奇怪,但是没有有用的文档说明应该传递什么参数。希望这对你有帮助