2012-07-25 101 views
-1

我已经通过邮局Upload to Facebook走了,但我在哪里调用功能uploadvideo ..
我还引进了Facebook SDK和示例项目工作区将请帮助我。 我已将代码添加到AsyncFacebookRunner类中,如果我已将代码复制到别处。视频上传到Facebook的问题

这是我的代码,我已经复制到AsyncFacebookRunner类

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

    } 

    } 

,这是我使用我的呼唤的onclick

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

我的疑问是,“MI正确地调用该函数因为一旦我运行这个我得到一个错误,说uploadVideosFacebook方法应该转换为静态我不认为这是正确的。

回答

0

按照这个答案,而不是:Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

基本上,你必须使用AsyncFacebookRunner与参数消息,文件名数据。消息是视频中的短消息,文件名是文件类型(例如:“.mp4”),数据是转换为字节后的视频。

使用AsyncFacebookRunner将此内容发布到“我/视频”。

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

+0

这是整个后,我已经使用 – Smaran 2012-07-25 14:30:48

+0

后你的代码。 – Tushar 2012-07-25 14:31:31

+0

我现在已经发布 – Smaran 2012-07-25 14:39:24