通过facebook sdk将视频上传到Facebook

时间:2011-12-07 14:02:01

标签: android facebook

我想将视频发布到Facebook墙上,任何人都可以建议我如何做到这一点。我尝试使用以下代码,但它无法正常工作。如果可能,请提供一些示例代码 我成功地将图像和消息发布在墙上,但我无法发布视频。我过去两天一直在努力但没有用。这是我的示例代码

private void postToFacebook() { 
    mProgress.setMessage("Posting ...");
    mProgress.show();
    byte[] data = null;
    InputStream is = null; 
    try{
    is = new FileInputStream("/mnt/sdcard/DCIM/100MEDIA/VIDEO0001.3gp");   
    data = readBytes(is); 
    }catch(Exception e){}
    AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);

    Bundle params = new Bundle();

    params.putString("message","Some message");
    params.putString("name", "Dexter");
    params.putString("caption", "londatiga.net");
params.putString("description", "Dexter, seven years old dachshund who loves to catch cats, eat carrot and krupuk");
            params.putByteArray("video", data); 
mAsyncFbRunner.request("me/videos", params, "POST", new WallPostListener());
}
  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    
          MyByteArrayOutputStream byteBuffer = new MyByteArrayOutputStream();

        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();
         } 

private final class WallPostListener extends BaseRequestListener {
    public void onComplete(final String response) {
        mRunOnUi.post(new Runnable() {
            @Override
            public void run() {
                mProgress.cancel();

                Toast.makeText(TestPost.this, "Posted to Facebook", Toast.LENGTH_SHORT).show();
            }
        });

0 个答案:

没有答案