我使用facebook sdk 3.6在facebook上传了这些视频。我成功上传了视频,但我想在上传文件时共享该位置。怎么做?
我使用以下代码上传视频文件。我试过但我没有得到。请允许任何人帮助我。
try {
Request videoRequest = Request
.newUploadVideoRequest(session,
file,
new Request.Callback() {
@Override
public void onCompleted(
Response response) {
if (response
.getError() == null) {
Toast.makeText(
AndroidCamera.this,
"video shared successfully",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(
AndroidCamera.this,
response.getError().getErrorMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
Bundle parameters = videoRequest.getParameters();
parameters.putString("caption",
"Video");
if (Nim_Constants.bUseLocation) {
parameters.putString("name",
Nim_Constants.Location);
}
parameters
.putString("link",
"https://developers.facebook.com/android");
videoRequest.setParameters(parameters);
// Execute the request in a separate thread
videoRequest.executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
答案 0 :(得分:0)
最后我找到了解决方案。这很简单。使用Request类而不是使用newUploadVideoRequest()方法,因为它不允许传递title,description之类的参数。因此,如果要设置标题,请使用Request类。为此,只需将文件传递为ParcelFileDescriptor并传递位置(您必须传递的内容)作为描述。
Upload Video on Facebook
文件文件=新文件(文件路径); 试试{
ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY);
Bundle parameters = new Bundle();
parameters.putParcelable(file.getName(),descriptor);
parameters.putString("description","Location");
Request videoRequest = new Request(session,"me/videos", parameters,HttpMethod.POST,
new Request.Callback() {
@Override
public void onCompleted(
Response response) {
if (response.getError() == null) {
Toast.makeText(
AndroidCamera.this,
"video shared successfully",
Toast.LENGTH_SHORT)
.show();
} else {
System.out
.println(response
.getError()
.getErrorMessage());
Toast.makeText(
AndroidCamera.this,
response.getError()
.getErrorMessage(),
Toast.LENGTH_SHORT)
.show();
}
}
});
// Execute the request in a separate thread
videoRequest.executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}