gpt4 book ai didi

android - Facebook android sdk 的 Session.requestNewPublishPermissions 给出了一个异常

转载 作者:行者123 更新时间:2023-11-29 01:56:07 26 4
gpt4 key购买 nike

我正在将 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;
}
}

最佳答案

登录后请求发布权限

这是我的代码

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);
}

}

关于android - Facebook android sdk 的 Session.requestNewPublishPermissions 给出了一个异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15055713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com