我已完成帖子Upload to 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方法应该转换为静态我不认为这是正确的。
答案 0 :(得分: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/