我已經通過郵局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方法應該轉換爲靜態我不認爲這是正確的。
這是整個後,我已經使用 – Smaran 2012-07-25 14:30:48
後你的代碼。 – Tushar 2012-07-25 14:31:31
我現在已經發布 – Smaran 2012-07-25 14:39:24