我正在将facebook集成到我的Android应用程序中,当用户第一次登录时,我正在使用requestFacebookPermissions(session)方法请求publish_actions权限。但每当我打电话给这个方法时,它就会给我以下异常......
java.lang.UnsupportedOperationException: Session: an attempt was made to request new permissions for a session that has a pending request.
我没有任何待处理的其他请求,可能是其他一些内部请求,但如何在不获取此异常的情况下请求权限?如果我必须等到其他请求完成,这是可以的,但我不知道如何完成待处理的请求。
private void requestFacebookPermissions(Session session) {
if (session != null && session.getState().isOpened()) {
List<String> permissions = session.getPermissions();
Log.i("Facebook", "Permissions Count: " + permissions.size());
for (String string : permissions) {
Log.i("FacebookPermissions", string);
}
if (!permissions.containsAll(PERMISSIONS)) {
try {
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(FacebookActivity.this, PERMISSIONS));
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
return;
}
}
答案 0 :(得分:1)
登录后我要求发布权限
这是我的代码
public class FacebookAccount extends FragmentActivity {
private UserSettingsFragment userSettingsFragment;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.facebook_login);
FragmentManager fragmentManager = getSupportFragmentManager();
userSettingsFragment = (UserSettingsFragment) fragmentManager
.findFragmentById(R.id.login_fragment);
userSettingsFragment.setReadPermissions(Utility.READ_PERMISSIONS);
userSettingsFragment
.setSessionStatusCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (state == SessionState.OPENED
&& !session.getPermissions().containsAll(
Utility.PUBLISH_PERMISSIONS)) {
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(
FacebookAccount.this,
Utility.PUBLISH_PERMISSIONS));
}
if (session.isOpened()
&& state == SessionState.OPENED_TOKEN_UPDATED) {
....Save session access token
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (userSettingsFragment != null)
userSettingsFragment
.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
}