2012-07-25 100 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