我正在尝试立即请求刚刚创建的用户会话的发布权限并收到以下错误,因为会话状态是“已创建”而不是“已打开”
"Session: an attempt was made to request new permissions for a session that is not currently open."
如何立即请求发布权限?有什么方法可以授权新用户并在一次调用中获得发布权限?
最终会话会话 = Session.getActiveSession(); if (session.isOpened()) { shareToFacebook(loadedImage, shareBody, session); } 别的 {
final StatusCallback callback = new StatusCallback() {
public void call(Session thisSession, SessionState state, Exception exception) {
if (exception != null) {
Toast.makeText(getApplicationContext(), "Facebook permissions failed: " + exception.getMessage(),
Toast.LENGTH_SHORT).show();
}
else
{
shareToFacebook(loadedImage, shareBody, thisSession);
}
}
};
//up the permissions and then post
if (session != null && !isSubsetOf(PERMISSIONS, session.getPermissions())) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(ActivityFacts.this, PERMISSIONS);
session.addCallback(callback);
session.requestNewPublishPermissions(newPermissionsRequest);
}
else
{
//add user then up the permissions
StatusCallback authorizeCallback = new StatusCallback() {
public void call(Session thisSession, SessionState state, Exception exception) {
if (exception != null) {
Toast.makeText(getApplicationContext(), "Facebook login failed: " + exception.getMessage(),
Toast.LENGTH_SHORT).show();
}
else
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(ActivityFacts.this, PERMISSIONS);
session.addCallback(callback);
session.requestNewPublishPermissions(newPermissionsRequest);
}
}
};
OpenRequest openRequest = new OpenRequest(ActivityFacts.this);
List<String> readPermissions = new ArrayList<String>();
readPermissions.add("email");
openRequest.setPermissions(readPermissions);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
openRequest.setCallback(authorizeCallback);
session.openForRead(openRequest);
}
}