1

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.

Adly
  • 597
  • 3
  • 12
  • 23
  • possible duplicate of [Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?](http://facebook.stackoverflow.com/questions/6908413/is-uploading-videos-from-an-sd-card-to-facebook-possible-with-the-facebook-sdk) – Juicy Scripter Feb 12 '12 at 17:48
  • I read that before but Thanks for the hint, I will try to check it again :) – Adly Feb 13 '12 at 12:17
  • If you are just want to post the Video then refer this answer: http://stackoverflow.com/questions/10151708/upload-video-to-facebook-in-android/12470730#12470730 – Shreyash Mahajan Dec 28 '12 at 05:41

2 Answers2

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();
}
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();
}
iamnaran
  • 1,894
  • 2
  • 15
  • 24
  • Your answer could use some bits of explanation for the posted code. This would help the OP more to understand your solution. :) – Markus Sep 06 '17 at 11:03