我想知道是否有人知道如何使用android sdk在Facebook上我的墙上传视频 我搜索了很多,但没有代码适合我。
我尝试了用于上传图片的facebook android sdk示例“Hackbook”,但我没有找到任何关于使用Android Sdk上传视频的详细教程!
因此,如果有人知道如何通过一段代码或类似的东西来做到这一点,那将非常好。
谢谢你们。
答案 0 :(得分:3)
byte[] data = null;
String dataPath = "/mnt/sdcard/KaraokeVideos/myvideo.3gp";
String dataMsg = "Your video description here.";
Bundle param;
facebook = new Facebook(FB_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
InputStream is = null;
try {
is = new FileInputStream(dataPath);
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putByteArray("video", data);
mAsyncRunner.request("me/videos", param, "POST", new fbRequestListener(), null);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
答案 1 :(得分:0)
private void uploadVideo() {
try {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
String title = "My titles";
String description = "My description";
JSONObject jsonObject = new JSONObject();
jsonObject.put("value", "EVERYONE");
byte[] data = readBytes(reversedPath);
GraphRequest request = GraphRequest.newPostRequest(accessToken, "me/videos", null, this);
Bundle params = request.getParameters();
params.putByteArray("video.mov", data);
params.putString("title", title);
params.putString("privacy", jsonObject.toString());
params.putString("description", description);
params.putInt("file_size", data.length);
request.setParameters(params);
request.executeAsync();
progressBarHorizonatl.setVisibility(View.VISIBLE);
} catch (JSONException | IOException e) {
e.printStackTrace();}
}}
public byte[] readBytes(String dataPath) throws IOException {
InputStream inputStream = new FileInputStream(dataPath);
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
return byteBuffer.toByteArray();
}