我想從我的廚房到的Facebook牆上這裏上傳視頻是我的代碼從android設備上的Facebook牆上上傳視頻?
byte[] data = null;
String dataPath = "/mnt/sdcard/DCIM/Camera/video-2012-09-03-13-34-19.mp4";
Bundle param;
//video extension
data Name = ".mp4"
facebook = new Facebook(FB_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
InputStream is = null;
try {
is = new FileInputStream(dataPath);
data = readBytes(is);
param = new Bundle();
param.putString("message", "hello guys");
param.putString("filename", data Name);
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();
}
首先我得到這樣的警告日誌貓
W/Bundle ( 774): Attempt to cast generated internal exception:
W/Bundle ( 774): java.lang.ClassCastException: java.lang.String
W/Bundle ( 774): at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle ( 774): at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle ( 774): at com.facebook.android.Facebook.request(Facebook.java:751)
W/Bundle ( 774): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
W/Bundle ( 774): Key format expected byte[] but value was a java.lang.String. The default value <null> was returned.
W/Bundle ( 774): Attempt to cast generated internal exception:
W/Bundle ( 774): java.lang.ClassCastException: java.lang.String
W/Bundle ( 774): at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle ( 774): at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle ( 774): at com.facebook.android.Facebook.request(Facebook.java:751)
我在谷歌搜索一些人建議有錯誤在Facebook的API,他們建議我修改一些線在我Util.java
for (String key : parameters.keySet()) {
if (parameters.get(key) instanceof byte[]) {
continue;
}
sb.append("Content-Disposition: form-data; name=\"" + key
+ "\"\r\n\r\n" + parameters.getString(key));
sb.append("\r\n" + "--" + boundary + "\r\n");
}
return sb.toString();
}
和
for (String key : params.keySet()) {
if (params.get(key) instanceof byte[]) {
dataparams.putByteArray(key, params.getByteArray(key));
}
}
現在我沒有得到任何警告任何錯誤,但我的影片不上傳,請幫助我,我在這裏打。
在此先感謝
好的,但爲什麼?我的視頻沒有上傳 – NareshRavva