-1

I have gone through the post Upload to Facebook but where do i call the function of uploadvideo..
I have also imported the facebook sdk and the sample project into workspace pls help me. I have added the code into the AsyncFacebookRunner class should i have copied the code somewhere else.

This is my code that i have copied to AsyncFacebookRunner class

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

    String dataMsg = "Video Desc.";
    String dataName="aaaassss.mp4";
    Bundle param;

    AsyncFacebookRunner mAsyncRunner = new   AsyncFacebookRunner(fb);
    InputStream is = null;
    try {
       is = new FileInputStream("/mnt/sdcard/aaaassss.mp4");
       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);

    }

    }

and this is what i use when i call the onclick

public void onClick(View v) 
{
                  AsyncFacebookRunner.uploadVideosFacebook("/mnt/sdcard/aaaassss.mp4");
           }

My doubt is that 'm i calling the function correctly as once i run this i get an error saying the uploadVideosFacebook method should be converted to static i dont think this is right.

Community
  • 1
  • 1
Smaran
  • 1,651
  • 2
  • 11
  • 15

1 Answers1

0

Follow this answer instead: Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

Basically you have to use AsyncFacebookRunner with the parameters message, filename, and data. Message is the short message to go with your video, filename is the type of file (ex: ".mp4"), and data is your video after converting into bytes.

Use AsyncFacebookRunner to POST this to "me/videos".

Reference: https://developers.facebook.com/docs/reference/rest/video.upload/

Community
  • 1
  • 1
Tushar
  • 8,019
  • 31
  • 38
  • This is the whole post that i have used – Smaran Jul 25 '12 at 14:30
  • Change your onClick to simply be: uploadVideosFacebook(String); You do not need the AsyncFacebookRunner. Can you try sending a 3gp video instead? There may be a bug with mp4 videos on Facebook's end. – Tushar Jul 25 '12 at 14:47
  • I'm calling the function in other class so i use it that way – Smaran Jul 25 '12 at 14:55
  • Don't put uploadVideosFacebook() in the AsyncRunnerFacebook class. Put it in a import class you have or just in the Activity itself. – Tushar Jul 25 '12 at 14:57