gpt4 book ai didi

android - 上传视频到 Facebook

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:19:15 27 4
gpt4 key购买 nike

我正在尝试使用以下代码将视频上传到 facebook

public void uploadVideosFacebook(String videoPath)
{
byte[] data = null;

String dataMsg = "Your video description here.";
String dataName="Mobile.wmv";
Bundle param;

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(API);
InputStream is = null;
try {
is = new FileInputStream(videoPath);
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);

}

}

但我收到以下错误消息作为回应{"error":{"type":"OAuthException","message":"(#352) 不支持视频文件格式"}}

谁能帮帮我。预先感谢您的帮助。

最佳答案

请参阅此链接 Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

我尝试了此链接中提到的所有内容,但遇到了与您相同的错误。然后我清理 Facebook 引用项目并重新构建它。我的问题已经解决了。现在可以上传视频了。

关于android - 上传视频到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7279510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com