简体   繁体   中英

Android Google plus sign in button

Following Google Sign Button , I implemented it on my android device.

When clicking the button it shows you a popup asking your permission: Know Who you are on Google.

Now what? It looks like this gives me nothing. It does not provide me access_token, or any user data.

What is it good for?

*Please do not tell me how to get access_token this is not what the question is about

You have to implement ConnectionCallbacks. And in onConnected(), you can start to get user data you want from the google plus account. Here's my sample code for the function:

    @Override
public void onConnected(Bundle connectionHint) {
    // We've resolved any connection errors.
    mConnectionProgressDialog.dismiss();
    String accountName = mPlusClient.getAccountName();
    Person p = mPlusClient.getCurrentPerson();
    String displayName = p.getDisplayName();
    google_text.setText(String.format("email:%s\ndisplay name:%s",accountName, displayName));

}

You can see more Person data in Google's link: Person

Your class must implements ConnectionCallbacks and one of provided methods is onConnected() method. When the flow reaches your implementation of onConnected() method (which means that you have successfully established connection with google) you can call lets say mPlusClient.getCurrentPerson(). The return type is instance of Person class where you can find anything about person who chose google plus login.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM