Google authorization process through account manager:
Email ID can be obtained from
AccountManager accountManager = AccountManager.get(getApplicationContext()); Account[] accounts = accountManager.getAccountsByType("com.google"); String emailID = accounts[0].name;
These lines must be run in a separate token (not in the user interface thread).
String scope = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com"; String accessToken = GoogleAuthUtil.getToken(mContext, emailID, scope);
save accessToken and use to access api.
After one hour (i.e. 3600 seconds), we need to update the access token. But now Google does not support access after an hour. We must restart the application and use the following lines to access the token.
String scope = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com"; String accessToken = GoogleAuthUtil.getToken(mContext, emailID, scope);
This background thread will always run in the background during the loop.
source share