I am new to using API in Java. I need to access Uber API's for my project and I am using Uber Java SDK from - https://github.com/uber/rides-java-sdk
I am following their steps but somehow getting error for Authenticating credentials. following are my steps:
1) Creating OAuth2Credentials object
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) Navigate the user to the authorization URL from the OAuth2Credentials object.
String authorizationUrl = credentials.getAuthorizationUrl();
3) Once the user approves the request, you get an authorization code. Create a credential object to store the authorization code and the user ID.
Credential credential = credentials.authenticate(authorizationCode, userId);
** i am using "authorizationCode" returned to my REDIRECT_URL ** I am NOT sure what userID should be??
But really code fails at STEP 3 with error:
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)
*** Please HELP:
1) How to resolve above error - am I doing anything wrong? 2) Are my steps correct? 3) What should be the UserID and where can i get that?
In order to get the user uuid you need to take the access token you get and make a request to https://developer.uber.com/docs/rides/api/v1-me.
UserProfile userProfile = uberRidesService.getUserProfile().execute().body();
See the java sample app included in the sdk: https://github.com/uber/rides-java-sdk/blob/master/samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/SampleServlet.java