立即使用android sdk在facebook会话上请求发布权限

时间:2013-02-22 21:34:09

标签: android facebook

我正在尝试立即请求刚创建的用户会话的发布权限并收到以下错误,因为会话状态为“已创建”而非“已打开”

"Session: an attempt was made to request new permissions for a session that is not currently open."

如何立即要求发布权限?有什么方法可以授权新用户并在一次通话中获得发布权限吗?

最后的Session session = 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);
}

}

0 个答案:

没有答案