以下是我检索用户个人资料的代码。我的登录成功,但当我尝试获取电子邮件地址时,我收到上述错误:
private void initializeUber(){
if(!UberSdk.isInitialized()) {
SessionConfiguration config = new SessionConfiguration.Builder()
// mandatory
.setClientId(AppConstants.UBER_CLIENT_ID)
// required for enhanced button features
.setServerToken(AppConstants.UBER_SERVER_TOKEN)
// required scope for Ride Request Widget features
.setScopes(Arrays.asList(Scope.PROFILE))
// optional: set Sandbox as operating environment
.setEnvironment(SessionConfiguration.Environment.SANDBOX)
.build();
UberSdk.initialize(config);
}
}
private void checkLoginForUber() {
LoginCallback loginCallback = new LoginCallback() {
@Override
public void onLoginCancel() {
// User canceled login
Log.i(TAG, "login cancelled");
}
@Override
public void onLoginError(@NonNull AuthenticationError error) {
// Error occurred during login
Log.i(TAG, error.toString());
Log.i(TAG, "login failed");
}
@Override
public void onLoginSuccess(@NonNull AccessToken accessToken) {
// Successful login! The AccessToken will have already been saved.
Log.i(TAG, "login successful");
getUserProfile();
}
@Override
public void onAuthorizationCodeReceived(@NonNull String authorizationCode) {
Log.i(TAG, authorizationCode);
}
};
accessTokenManager = new AccessTokenManager(this);
loginManager = new LoginManager(accessTokenManager, loginCallback);
loginManager.login(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
loginManager.onActivityResult(this, requestCode, resultCode, data);
}
private void getUserProfile(){
try {
AccessToken accessToken = accessTokenManager.getAccessToken();
Log.i(TAG,accessToken.getToken());
Session session = loginManager.getSession();
AppContext.getmInstance().setSession(session);
//Intent intent = new Intent(this, UbserService.class);
//startService(intent);
RidesService service = UberRidesApi.with(session).build().createService();
service.getUserProfile().enqueue(new Callback<UserProfile>() {
@Override
public void onResponse(Call<UserProfile> call, Response<UserProfile> response) {
Log.i(TAG, response.toString());
if (response.isSuccessful()) {
//Success
UserProfile profile = response.body();
Log.i(TAG,profile.getEmail());
} else {
//Api Failure
ApiError error = ErrorParser.parseError(response);
for (int i = 0; i < error.getClientErrors().size(); i++) {
Log.i(TAG, error.getClientErrors().get(i).getTitle());
}
}
}
@Override
public void onFailure(Call<UserProfile> call, Throwable t) {
//Network Failure
}
});
}catch (Exception ex){
ex.printStackTrace();
}
}
我在这做什么?该应用程序重定向到Uber应用程序,我在其中授予访问以获取用户信息的权限。在我回到我的应用程序后,调用了登录成功,但是当我调用getUserProfile时,我收到此错误。我正在使用SSO进行身份验证。