视频上传到Facebook的问题 [英] Upload Video to Facebook Problems
问题描述
我已经通过邮局上传到Facebook ,但我在哪里可以调用的功能 uploadvideo 的 ..结果
我还导入了Facebook的SDK和示例项目工作区到请帮助我。
我已经加入了code到AsyncFacebookRunner类应该我抄code别处。
I have gone through the post Upload to Facebook but where do i call the function of uploadvideo..
I have also imported the facebook sdk and the sample project into workspace pls help me.
I have added the code into the AsyncFacebookRunner class should i have copied the code somewhere else.
这是我的,我已经复制到AsyncFacebookRunner类code
This is my code that i have copied to AsyncFacebookRunner class
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我使用
and this is what i use when i call the onclick
public void onClick(View v)
{
AsyncFacebookRunner.uploadVideosFacebook("/mnt/sdcard/aaaassss.mp4");
}
我的疑问是,M我正确地调用该函数因为一旦我运行此我得到一个错误说的uploadVideosFacebook方法应该转换为静态我不认为这是正确的。
My doubt is that 'm i calling the function correctly as once i run this i get an error saying the uploadVideosFacebook method should be converted to static i dont think this is right.
推荐答案
按照这个答案,而不是:<一href=\"http://stackoverflow.com/questions/6908413/is-uploading-videos-from-an-sd-card-to-facebook-possible-with-the-facebook-sdk\">Is从SD卡给Facebook可能与Facebook的SDK上传视频?
Follow this answer instead: Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?
基本上,你必须使用AsyncFacebookRunner带参数的消息,文件名和数据即可。消息是短消息去与你的视频,文件名是文件(例如:.MP4)的类型,并将其转换成字节后数据为您的视频
Basically you have to use AsyncFacebookRunner with the parameters message, filename, and data. Message is the short message to go with your video, filename is the type of file (ex: ".mp4"), and data is your video after converting into bytes.
使用AsyncFacebookRunner发布此为我/录像。
Use AsyncFacebookRunner to POST this to "me/videos".
参考: https://developers.facebook.com/文档/参考/ REST / video.upload /
Reference: https://developers.facebook.com/docs/reference/rest/video.upload/
这篇关于视频上传到Facebook的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!