Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

android - Upload Video to Facebook Problems

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...