我在 log cat 中收到错误
{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 353, errorType: OAuthException, errorMessage: (#353) Missing video file}, isFromCache:false}
使用下面的方法
private void postVideo() {
try {
File file = new File(videoPath);
ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
Bundle parameters = new Bundle(1);
parameters.putParcelable(file.getName(), descriptor);
new Request(Session.getActiveSession(), "me/videos", parameters, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
Constants.showLog(TAG, "In Response " + response.getGraphObject().getProperty("id"));
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
Constants.showLog(TAG, "In Response id " + postId);
} catch (JSONException e) {
Constants.showLog(TAG,"JSON error "+ e.getMessage());
}
}
}).executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
请帮忙
最佳答案
我看到您使用的是 Android SDK 3.0,我们随附了一种上传视频的简单方法。这是我用来将视频上传到 Facebook 的代码:
Request.Callback callback5 = new Request.Callback() {
public void onCompleted(Response response) {
// response will have an id if successful
}
};
File tempFile;
try {
tempFile = Util.createTempFileFromAsset(getApplicationContext(), "video.mp4");
Request request5 = Request.newUploadVideoRequest(session,
tempFile, callback5);
RequestAsyncTask task5 = new RequestAsyncTask(request5);
task5.execute();
} catch (IOException e) {
Log.e(Util.TAG, "failed to create temp file");
e.printStackTrace();
}
和 createTempFileFromAsset
的代码:
public static File createTempFileFromAsset(Context context, String assetPath)
throws IOException {
InputStream inputStream = null;
FileOutputStream outStream = null;
try {
AssetManager assets = context.getResources().getAssets();
inputStream = assets.open(assetPath);
File outputDir = context.getCacheDir(); // context being the
// Activity pointer
File outputFile = File.createTempFile("prefix", assetPath,
outputDir);
outStream = new FileOutputStream(outputFile);
final int bufferSize = 1024 * 2;
byte[] buffer = new byte[bufferSize];
int n = 0;
while ((n = inputStream.read(buffer)) != -1) {
outStream.write(buffer, 0, n);
}
return outputFile;
} finally {
Utility.closeQuietly(outStream);
Utility.closeQuietly(inputStream);
}
}
关于android - 使用 fb sdk 在 facebook 墙上发布视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14055996/