在Facebook 2.5图形API中,无论何时发布发布请求,您都必须像这样调用请求方法 -
Util.parseJson(facebook.request("me/photos", parameters,"POST"));
如果您已获得授权,Facebook将自动发布照片(或文本)。
但是在每次发送请求的新图API 3.0中,Facebook都会打开授权对话框。我可以发布照片和视频,但如果会话在授权后已经打开,我不想打开对话框。这是我的代码 -
private void uploadVideo() {
final Session session = Session.getActiveSession();
final Request request;
if(session.isOpened())
{
OpenRequest openRequest = new OpenRequest(getActivity());
openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
openRequest.setCallback(null);
List<String> PERMISSIONS = new ArrayList<String>();
PERMISSIONS.add("publish_stream");
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
Callback callback = new Callback() {
@Override
public void onCompleted(Response response) {
System.out.println(response.toString());
}
};
File file = new File(Environment.getExternalStorageDirectory()+"/123.mp4");
if(file.exists())
{
try {
request = Request.newUploadVideoRequest(session, file, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
我尝试更换这两行 -
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
用这个 -
openRequest.setPermissions(PERMISSIONS);
通过执行此操作,它不显示授权对话框,但成功率为2 out 3.有时响应消息状态 -
发生意外错误。