我正在配置具有請求範圍(受限)的uber sdk。在LoginManager回調方法onAuthorizationCodeReceived()我得到authorizationCode作爲參數,而onLoginSuccess()回調方法沒有被調用。如何在登錄回撥中使用授權碼獲取UBER訪問令牌
這裏是我的代碼...
config = initialiseUberSDK();
accessTokenManager = new AccessTokenManager(this);
loginManager = new LoginManager(accessTokenManager,
new LoginCallback() {
@Override
public void onLoginCancel() {
Toast.makeText(CustomActivity2.this, "Login cancelled", Toast.LENGTH_LONG).show();
}
@Override
public void onLoginError(@NonNull AuthenticationError error) {
Toast.makeText(CustomActivity2.this,
"Error: "+error.name(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onLoginSuccess(@NonNull AccessToken accessToken) {
Toast.makeText(CustomActivity2.this, "Login success",
Toast.LENGTH_LONG)
.show();
createSession();
}
@Override
public void onAuthorizationCodeReceived(@NonNull String authorizationCode) {
Toast.makeText(CustomActivity2.this, "Your Auth code is: "+authorizationCode,
Toast.LENGTH_LONG)
.show();
}
},
config,
1113).setRedirectForAuthorizationCode(true);
customButton = (Button) findViewById(R.id.button);
customButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginManager.login(CustomActivity2.this);
}
});
這裏是initialiseUberSDK()方法...
private SessionConfiguration initialiseUberSDK() {
config = new SessionConfiguration.Builder()
.setClientId(getResources().getString(R.string.client_id))
// .setServerToken(getResources().getString(R.string.server_token))
// .setClientSecret(getResources().getString(R.string.client_secret))
.setRedirectUri(getResources().getString(R.string.redirect_url))
.setEnvironment(SessionConfiguration.Environment.SANDBOX)
.setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS, Scope.REQUEST))
.build();
// UberSdk.initialize(config);
return config;
}
這裏onLoginSuccess()方法永遠不會被調用。只有onAuthorizationCodeReceived()方法被調用(訪問令牌對象爲空)。
我的問題是
如何使用授權碼生成訪問令牌?
下面是onAuthorizationCodeReceived()方法的Java文檔...
*
公共無效onAuthorizationCodeReceived(@NonNull字符串 authorizationCode)
從接口複製: LoginCallback授權碼返回到重定向uri時調用。的accessToken 必須使用客戶端密鑰被檢索,見 https://developer.uber.com/docs/authentication#section-step-two-receive-redirect 指定者: onAuthorizationCodeReceived接口LoginCallback 參數: authorizationCode - 可用於檢索的accessToken的authorizationCode
*