我刚开始在Java中使用API。我需要为我的项目访问优步API,我正在使用来自- https://github.com/uber/rides-java-sdk的优步Java。
我遵循他们的步骤,但不知何故,在认证凭据方面出现了错误。以下是我的步骤:
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 **我不确定userID应该是什么??
但是,真正的代码在第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应该是什么,从哪里可以得到?
发布于 2016-08-29 22:10:03
为了获得用户uuid,您需要获取所获得的访问令牌,并向https://developer.uber.com/docs/rides/api/v1-me发出请求。
UserProfile userProfile = uberRidesService.getUserProfile().execute().body();请参阅sdk:https://github.com/uber/rides-java-sdk/blob/master/samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/SampleServlet.java中包含的java示例应用程序。
https://stackoverflow.com/questions/39135908
复制相似问题