上传视频至Facebook [英] Upload Video to Facebook

查看:131
本文介绍了上传视频至Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的code上传视频至Facebook

I am trying to upload video to facebook using the following code

公共无效uploadVideosFacebook(字符串将videoPath)     {         byte []的数据= NULL;

public void uploadVideosFacebook(String videoPath) { byte[] data = null;

    String dataMsg = "Your video description here.";
    String dataName="Mobile.wmv";
    Bundle param;

    AsyncFacebookRunner mAsyncRunner = new   AsyncFacebookRunner(API);
    InputStream is = null;
    try {
       is = new FileInputStream(videoPath);
       data = readBytes(is); 

       param = new Bundle();
       param.putString("message", dataMsg);
       param.putString("filename", dataName);
       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();
}


public class fbRequestListener implements RequestListener {

    @Override
    public void onComplete(String response, Object state) {
        // TODO Auto-generated method stub
        Log.d("RESPONSE",""+response);

    }

    @Override
    public void onIOException(IOException e, Object state) {
        // TODO Auto-generated method stub
        Log.d("RESPONSE",""+e);

    }

    @Override
    public void onFileNotFoundException(FileNotFoundException e,
            Object state) {
        // TODO Auto-generated method stub
        Log.d("RESPONSE",""+e);

    }

    @Override
    public void onMalformedURLException(MalformedURLException e,
            Object state) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFacebookError(FacebookError e, Object state) {
        // TODO Auto-generated method stub
        Log.d("RESPONSE",""+e);

    }

    }

但我得到的响应以下错误信息 {错误:{类型:OAuthException,消息:不支持视频文件格式(#352)}}

But i am getting following error message in response {"error":{"type":"OAuthException","message":"(#352) Video file format is not supported"}}

您可以请帮我...在此先感谢您的帮助......

can you please help me out ...thanks in advance for your help....

推荐答案

看到该链接<一个href="http://stackoverflow.com/questions/6908413/is-uploading-videos-from-an-sd-card-to-facebook-possible-with-the-facebook-sdk">Is从SD卡向Facebook可能与Facebook的SDK上传视频?

我尝试了所有的东西,这是提到在这个环节,但我得到同样的错误,你。 然后我打扫Facebook的参考项目,然后重新构建它。我的概率是solved.now视频上传的工作。

i tried all stuff that was mention in this link but i was getting same error as you. then i clean Facebook reference project and build it again. and my prob was solved.now video uploading is working..

这篇关于上传视频至Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆