Reputation: 597
I wonder if someone know how to upload a video on my wall on facebook using android sdk I searched a lot but no code works for me.
I tried the facebook android sdk example which called "Hackbook" for uploading an image but I didn't found any detailed tutorial about uploading videos using Android Sdk!
So if some one know how to do that by a snippet of code or something like that, it will be very nice.
Thanks guys.
Upvotes: 1
Views: 1992
Reputation: 1963
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();
}
Upvotes: 0
Reputation:
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();
}
Upvotes: 3