我从我的应用程序上传视频并获取该视频的信息(赞,评论)
问题1
我已经完成了上传,但是当我收到视频信息时,它会引发错误
错误
{"error":{"message":"Cannot specify type in both the path and query parameter.","type":"OAuthException","code":2500}}
我正在使用 Facebook SDK 3.8
问题2 当我上传视频时,它只在我的帐户中显示,但在其他帐户中无法显示,即使它是公开的
上传视频代码
private void Upload_Video() {
mDialog = new ProgressDialog(AndroidFacebookConnectActivity.this);
mDialog.setMessage("Uploding video...");
mDialog.show();
String path="/mnt/sdcard/abc/Mirror.mp4";
if (new File(path).exists()) {
try {
Bundle param;
try {
InputStream is = new FileInputStream(path);
byte[] data = readBytes(is);
param = new Bundle();
param.putString("title", "Test 2");
param.putString("message", "uploaded");
param.putByteArray("video.mov", data);
param.putString("contentType", "video/quicktime");
mAsyncRunner.request("kmavadhiya/videos", param, "POST",new FBRequestListener(), null);
Toast.makeText(getApplicationContext(), "Uploading...", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), "No videos found in sdcard ",Toast.LENGTH_SHORT).show();
}
}
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) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(AndroidFacebookConnectActivity.this, "Upload Video Successfully...",Toast.LENGTH_LONG).show();
mDialog.dismiss();
}
});
Log.e("response", response);
try {
JSONObject jObject = new JSONObject(response);
String Id = (String) jObject.get("id");
Log.d("Video Id = ",""+Id);
Bundle param = new Bundle();
param.putString("type", "uploaded");
mAsyncRunner.request("kmavadhiya/videos/"+Id, param, "GET",new VideoDataRequestListener(), null);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onIOException(IOException e, Object state) {
e.printStackTrace();
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
Log.e("", "onFileNotFoundException");
e.printStackTrace();
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
Log.e("", "onMalformedURLException");
e.printStackTrace();
}
@Override
public void onFacebookError(FacebookError e, Object state) {
Log.e("", "onFacebookError");
e.printStackTrace();
}
}
视频数据列表器
public class VideoDataRequestListener implements RequestListener {
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
Log.e("response", response);
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
@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
}
}
如果我更改了此行
mAsyncRunner.request("kmavadhiya/videos/"+Id, param, "GET",new VideoDataRequestListener(), null);
。通过
mAsyncRunner.request("kmavadhiya/videos/", param, "GET",new VideoDataRequestListener(), null);
**我得到了空白回复**
参考 Link 1
答案 0 :(得分:0)
我忘记在登录时请求权限,因此其身份验证错误
在登录时添加此内容点击
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("basic_info","user_about_me","email","video_upload","user_videos")) // Permission List That You Want To Get
.setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
<强>参考强>
许可列表
https://developers.facebook.com/docs/facebook-login/access-tokens/
设置权限参考
https://developers.facebook.com/docs/android/login-with-facebook#permissions