Uber Rides JAVA SDK:无法请求令牌
Uber Rides JAVA SDK : Unable to request token
我刚开始在 Java 中使用 API。我需要为我的项目访问 Uber API,我正在使用来自 - https://github.com/uber/rides-java-sdk
的 Uber Java SDK
我正在按照他们的步骤操作,但不知何故在验证凭据时出错。以下是我的步骤:
1) 创建 OAuth2Credentials 对象
SessionConfiguration config = new SessionConfiguration.Builder()
.setClientId(CLIENT_ID)
.setClientSecret(MY_SECRET)
.setRedirectUri(REDIRECT_URL)
.setScopes(Arrays.asList(Scope.HISTORY, Scope.PROFILE, Scope.PLACES))
.build();
OAuth2Credentials credentials = new OAuth2Credentials.Builder()
.setSessionConfiguration(config)
.build();
2) 将用户从 OAuth2Credentials 对象导航到授权 URL。
String authorizationUrl = credentials.getAuthorizationUrl();
3) 用户批准请求后,您将获得授权码。创建一个凭据对象来存储授权码和用户 ID。
Credential credential = credentials.authenticate(authorizationCode, userId);
** 我正在使用 "authorizationCode" 返回到我的 REDIRECT_URL
** 我不确定用户 ID 应该是什么?
但实际上代码在第 3 步失败并出现错误:
HTTP ERROR 500
Problem accessing /hello. Reason:
Unable to request token.
Caused by:
com.uber.sdk.rides.auth.AuthException: Unable to request token.
at com.uber.sdk.rides.auth.OAuth2Credentials.authenticate(OAuth2Credentials.java:279)
at com.c2p.HelloAppEngine.doGet(HelloAppEngine.java:183)
*** 请帮助:
1) 如何解决上述错误 - 我做错了什么吗?
2)我的步骤正确吗?
3) UserID 应该是什么,我在哪里可以得到它?
为了获得用户 uuid,您需要获取您获得的访问令牌并向 https://developer.uber.com/docs/rides/api/v1-me 发出请求。
UserProfile userProfile = uberRidesService.getUserProfile().execute().body();
查看 SDK 中包含的 java 示例应用程序:https://github.com/uber/rides-java-sdk/blob/master/samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/SampleServlet.java
我刚开始在 Java 中使用 API。我需要为我的项目访问 Uber API,我正在使用来自 - https://github.com/uber/rides-java-sdk
的 Uber Java SDK我正在按照他们的步骤操作,但不知何故在验证凭据时出错。以下是我的步骤:
1) 创建 OAuth2Credentials 对象
SessionConfiguration config = new SessionConfiguration.Builder()
.setClientId(CLIENT_ID)
.setClientSecret(MY_SECRET)
.setRedirectUri(REDIRECT_URL)
.setScopes(Arrays.asList(Scope.HISTORY, Scope.PROFILE, Scope.PLACES))
.build();
OAuth2Credentials credentials = new OAuth2Credentials.Builder()
.setSessionConfiguration(config)
.build();
2) 将用户从 OAuth2Credentials 对象导航到授权 URL。
String authorizationUrl = credentials.getAuthorizationUrl();
3) 用户批准请求后,您将获得授权码。创建一个凭据对象来存储授权码和用户 ID。
Credential credential = credentials.authenticate(authorizationCode, userId);
** 我正在使用 "authorizationCode" 返回到我的 REDIRECT_URL ** 我不确定用户 ID 应该是什么?
但实际上代码在第 3 步失败并出现错误:
HTTP ERROR 500
Problem accessing /hello. Reason:
Unable to request token.
Caused by:
com.uber.sdk.rides.auth.AuthException: Unable to request token.
at com.uber.sdk.rides.auth.OAuth2Credentials.authenticate(OAuth2Credentials.java:279)
at com.c2p.HelloAppEngine.doGet(HelloAppEngine.java:183)
*** 请帮助:
1) 如何解决上述错误 - 我做错了什么吗? 2)我的步骤正确吗? 3) UserID 应该是什么,我在哪里可以得到它?
为了获得用户 uuid,您需要获取您获得的访问令牌并向 https://developer.uber.com/docs/rides/api/v1-me 发出请求。
UserProfile userProfile = uberRidesService.getUserProfile().execute().body();
查看 SDK 中包含的 java 示例应用程序:https://github.com/uber/rides-java-sdk/blob/master/samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/SampleServlet.java