With reference to this link, I integrated the Uber sdk into my app.before that I registered my application in the Uber developer site got my client id and the client secret.
I added the below code in my application class:
UberSdk.initialize(this, "MY_CLIENT_ID");
UberSdk.setRedirectUri("MY_REDIRECT_URI");
UberSdk.setSandboxMode(true);
Then in my fragment:
oncreate():
accessTokenManager = new AccessTokenManager(getContext());
loginManager = new LoginManager(accessTokenManager);
List<Scope> scopes = new ArrayList<Scope>();
scopes.add(Scope.PROFILE);
scopes.add(Scope.RIDE_WIDGETS);
Date expirationTime = new Date(System.currentTimeMillis());
String token = "Token";
AccessToken accessToken = new AccessToken(expirationTime, scopes, token);
accessTokenManager.setAccessToken(accessToken);
Log.d("ttt", "accessToken: " + accessTokenManager.getAccessToken());
loginManager.loginWithScopes(getActivity(), scopes);
onActivityResult():
LoginCallback loginCallback = new LoginCallback() {
@Override
public void onLoginCancel() {
// User canceled login
Log.d("ttt", " User canceled login " );
Toast.makeText(getContext(), "User canceled login", Toast.LENGTH_SHORT).show();
}
@Override
public void onLoginError(@NonNull AuthenticationError error) {
// Error occurred during login
Log.d("ttt", "Error occurred during login" );
Toast.makeText(getContext(),"Error occurred during login",Toast.LENGTH_SHORT).show();
}
@Override
public void onLoginSuccess(@NonNull AccessToken accessToken) {
// Successful login! The AccessToken will have already been saved.
Log.d("ttt", "Successful login! " );
Toast.makeText(getContext(),"Successful login!",Toast.LENGTH_SHORT).show();
}
};
loginManager.onActivityResult(requestCode, resultCode, data, loginCallback);
I have no idea how to add redirect uri and from where I will get the redirect uri. And what is the actual use of it (searched a lot still not clear with what it does).
Once I click the Uber ride button it navigates to some loginactivity and a popup shows up saying "There was a problem authenticating you".
What I am doing wrong here?