【问题标题】:Uploading a video or an image to facebook using Android SDK使用 Android SDK 将视频或图像上传到 Facebook
【发布时间】:2012-03-04 07:04:36
【问题描述】:

我想知道是否有人知道如何使用 android sdk 在我的 Facebook 墙上上传视频 我搜索了很多,但没有代码适合我。

我尝试了名为“Hackbook”的 facebook android sdk 示例来上传图片,但我没有找到任何关于使用 Android Sdk 上传视频的详细教程!

所以如果有人知道如何通过 sn-p 代码或类似的东西来做到这一点,那就太好了。

谢谢大家。

【问题讨论】:

标签: android facebook video sdk upload


【解决方案1】:
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();
}

【讨论】:

    【解决方案2】:
    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();
    }
    

    【讨论】:

    • 您的答案可能会对发布的代码进行一些解释。这将有助于 OP 更多地了解您的解决方案。 :)
    猜你喜欢
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多