In my GWT application, I am using the com.google.api.gwt.oauth2.OAuth2 module to allow users to signin with OAuth. I have implemented a GoogleApi class to provide the OAuth login as follows:
public final class GoogleApi {
private EventBus eventBus;
private final ClientOAuth2Login oAuth2Login;
private ClientGoogleApiRequestTransport requestTransport;
private String accessToken;
public GoogleApi(final EventBus eventBus, String clientId) {
this.eventBus = eventBus;
oAuth2Login = new ClientOAuth2Login(clientId);
}
...
public void login(final Receiver<String> callback) {
oAuth2Login.login(new Receiver<String>() {
@Override
public void onSuccess(String response) {
accessToken = response;
callback.onSuccess(response);
}
@Override
public void onFailure(ServerFailure error) {
Window.alert(error.getMessage());
}
});
}
...
}
I am calling this login() method as follows:
googleApi.login(new Receiver<String>() {
@Override
public void onSuccess(final String token) {
// I want to get the logged in user's name here
}
@Override
public void onFailure(ServerFailure error) {
...
}
});
After successful login, I want to get the logged in user's full name. I know that I can get the user's name using the com.google.api.gwt.services.Plus module, but that requires users to be registered to Google Plus and throws an error if they're not.
How can I do this using OAuth in my GWT app? Basically, I want to be able to implement this solution in a GWT app, if possible.