5

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

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

    }

    }

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

Can anyone help me out. Thanks in advance for your help.

Viral Savaj
  • 3,379
  • 1
  • 26
  • 39
Vishal
  • 51
  • 1
  • 3

2 Answers2

1

see this link Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

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..

Community
  • 1
  • 1
yasir
  • 11
  • 1
0

Is there anything strange about your video file? WMV should be supported by Facebook, but perhaps you're using a strange variant of WMV, one which is copy protected, etc? Have you tried the same code with another video?

Igy
  • 43,710
  • 8
  • 89
  • 115
  • thanks for the reply.....but that video is getting uploaded to other sites such as twitter... – Vishal Sep 02 '11 at 06:30
  • I'm not sure, then. If it's definitely working fine elsewhere, and there's nothing special about the video, it may be a bug in the video upload on Facebook's side, maybe file a detailed bug report and see if it can be reproduced? (http://bugs.developers.facebook.net/) – Igy Sep 03 '11 at 18:51