我已经完成了 上传到 Facebook的帖子,但是我在哪里调用uploadvideo的功能..
我还将 facebook sdk 和示例项目导入工作区,请帮助我。如果我将代码复制到其他地方,我已将代码添加到 AsyncFacebookRunner 类中。
这是我复制到 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");
}
我的疑问是,当我运行此函数时,我会正确调用该函数,我会收到一条错误消息,指出应该将 uploadVideosFacebook 方法转换为静态方法,我认为这是不正确的。