rah*_*ulg 5 android facebook facebook-graph-api facebook-android-sdk
我打电话时在Facebook Android SDK中
Session tempSession = new Builder(this).build();
Session.setActiveSession(tempSession);
tempSession.openForRead(new OpenRequest(this).setPermissions(FB_PERMISSIONS));
Run Code Online (Sandbox Code Playgroud)
它得到一个FB会话,每件事都正常运行.但是,当我更换Read使用Publish.即如下
Session tempSession = new Builder(this).build();
Session.setActiveSession(tempSession);
tempSession.openForPublish(new OpenRequest(this).setPermissions(FB_PERMISSIONS));
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误,即会话为空,并且无法获得空会话的发布权限.
你能告诉我为什么会这样,最好的办法是什么?
小智 7
我花了一段时间对其进行排序,以便用户可以点击按钮在Feed中共享我的一个产品.我不希望在他们真正想分享之前提示他们登录,所以我真的只是想要发布权限.以下内容将初始登录/读取权限请求与发布权限请求进行堆叠.这将双重提示用户,首先进行读取,然后进行发布,但无论解决方案如何,现在都需要:
Session session = Session.getActiveSession();
if (session == null) {
session = new Session.Builder(this).setApplicationId("<APP ID HERE>").build();
Session.setActiveSession(session);
session.addCallback(new StatusCallback() {
public void call(Session session, SessionState state, Exception exception) {
if (state == SessionState.OPENED) {
Session.OpenRequest openRequest = new Session.OpenRequest(FacebookActivity.this);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.requestNewPublishPermissions(
new Session.NewPermissionsRequest(FacebookActivity.this, PERMISSIONS));
}
else if (state == SessionState.OPENED_TOKEN_UPDATED) {
publishSomething();
}
else if (state == SessionState.CLOSED_LOGIN_FAILED) {
session.closeAndClearTokenInformation();
// Possibly finish the activity
}
else if (state == SessionState.CLOSED) {
session.close();
// Possibly finish the activity
}
}});
}
if (!session.isOpened()) {
Session.OpenRequest openRequest = new Session.OpenRequest(this);
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.openForRead(openRequest);
}
else
publishSomething();
Run Code Online (Sandbox Code Playgroud)
简短的回答是,不要调用 openForPublish。调用 openForRead,然后如果需要发布权限,请稍后请求 NewPublishPermissions。
长的答案是,你不能请求发布权限(对于以前从未通过你的应用程序连接过 Facebook 的用户),除非你已经拥有基本或默认权限(如果你使用空权限集调用 openForRead 会得到什么) 。因此 openForPublish 实际上处理了大多数应用程序可能没有的非常具体的利基用例。
| 归档时间: |
|
| 查看次数: |
6797 次 |
| 最近记录: |