我真的需要关闭一个会话(比如从一个 READ 会话),并建立一个新的 PUBLISH 活动会话,以便我执行 publish_stream 请求。
如果是(或不是),我有什么有效的方法吗?
我真的需要关闭一个会话(比如从一个 READ 会话),并建立一个新的 PUBLISH 活动会话,以便我执行 publish_stream 请求。
如果是(或不是),我有什么有效的方法吗?
不需要。打电话session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));
其中PERMISSIONS是(相应地改变它):
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
完成后,您将收到回调:
SessionState.OPENED_TOKEN_UPDATED
检查上述状态并通过调用再次发布您的消息:
Request statusRequest=Request.newStatusUpdateRequest(Session.getActiveSession(), mStatus.getText().toString(), reqestCallback);
if(statusRequest!=null){
statusRequest.executeAsync();
private class App_Session_StatusCallback implements Session.StatusCallback
{
@Override
public void call(Session session, SessionState state, Exception exception)
{
Log.d("asd", "state changed");
handleSessionStateChanged(session, state, exception);
}
}
private void handleSessionStateChanged(Session session, SessionState state, Exception exception)
{
if(state == SessionState.OPENED_TOKEN_UPDATED)
{
Request statusRequest=Request.newStatusUpdateRequest(Session.getActiveSession(), mStatus.getText().toString(), reqestCallback);
if(statusRequest!=null){
statusRequest.executeAsync();
}
}
if(session != null)
{
if(session.isOpened())
{
Log.d("asd", "session is opened");
Log.d("asd", "Token = " + session.getAccessToken());
Log.d("asd", "Expiry = " + session.getExpirationDate().toGMTString());
}
else
{
Log.d("asd", "session is NOT opened");
}
}
}
Session.getActiveSession().requestNewPublishPermissions(new Session.NewPermissionsRequest(this, Arrays.asList("publish_actions")));