问题
I successfully implemented Google Account sign in using the tutorial here for Android:
https://developers.google.com/appengine/docs/java/endpoints/getstarted/clients/android/add_auth_code
This allows my app to successfully use endpoints in app engine while authenticated.
However now I'd like to perform some Google Plus functionality, ie: obtain some info about the user. I followed the code for the G+ signin as below:
https://developers.google.com/+/mobile/android/getting-started#step_4_initialize_the_googleapiclient
What I'd like to know is if these 2 methods can somehow be merged? I feel like I'm asking the user to sign in twice with his Google account... Is there anyway the GoogleApiClient of G+ can be used to generate the credentials needed for the Google Endpoints authentication?
回答1:
Once signed in using Google+, you're almost good to go to talk to your Backend API. Something like this was what I did:
@Override
public void onConnected(Bundle bundle) {
// Update the user interface to reflect that the user is signed in.
mSignInProgress = STATE_DEFAULT;
if (BuildConfig.DEBUG) {
Log.i(LOG_TAG, "Signed in");
}
final String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
credential.setSelectedAccountName(accountName); // private GoogleAccountCredential credential;
// call your GAE stuff
}
来源:https://stackoverflow.com/questions/25656511/can-i-use-google-plus-sign-in-to-authenticate-my-oauth-methods-in-app-engine