在Android的Facebook墙上发布视频

时间:2012-05-28 06:22:41

标签: android facebook-graph-api

我只是想从我的Android应用程序发布这个视频到Facebook墙。当用户在Facebook上点击它时,该视频应该在线播放。我怎么能这样做?

我的代码:

byte[] data = null;
String dataPath = "My Video URL here";
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();
}


public byte[] readBytes(InputStream inputStream) throws IOException {
    // This dynamically extends to take the bytes you read.
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();

    // This is storage overwritten on each iteration with bytes.
    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];

    // We need to know how may bytes were read to write them to the byteBuffer.
    int len = 0;
    while ((len = inputStream.read(buffer)) != -1) {
        byteBuffer.write(buffer, 0, len);
    }

    // And then we can return your byte array.
    return byteBuffer.toByteArray();
}

0 个答案:

没有答案