當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleAuthUtil.getToken方法代碼示例

本文整理匯總了Java中com.google.android.gms.auth.GoogleAuthUtil.getToken方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleAuthUtil.getToken方法的具體用法?Java GoogleAuthUtil.getToken怎麽用?Java GoogleAuthUtil.getToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.auth.GoogleAuthUtil的用法示例。


在下文中一共展示了GoogleAuthUtil.getToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
private void getToken(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String email = sharedPreferences.getString(Constants.KEY_EMAIL, null);
    mUserGoogleId = sharedPreferences.getString(Constants.KEY_USER_GOOGLE_ID, null);
    mUserUID = sharedPreferences.getString(Constants.KEY_USER_UID, null); //firebase userId

    try {
        String scope = String.format("oauth2:%s", "https://picasaweb.google.com/data/");
        String token = null;
        if (email != null) {
            token = GoogleAuthUtil.getToken(context, email, scope);
        }

        Log.i(TAG, "Get Token\n" +
                "2 Picasa client " + mPicasaClient + "\n" +
                "2 Picasa service " + mPicasaService + "\n" +
                "--- Google token " + token);

        mPicasaClient.createService(token);
        mPicasaService = mPicasaClient.getPicasaService();
    } catch (IOException | GoogleAuthException e) {
        e.printStackTrace();
    }
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:25,代碼來源:SyncService.java

示例2: authenticate

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
@Override
public Request authenticate(Route route, Response response) throws IOException {
    Log.d(TAG, "Re-authenticating requests");
    if (responseCount(response) >= 3) {
        return null; // If we've failed 3 times, give up. - in real life, never give up!!
    } else {
        try {
            if (mContext == null)
                Log.d(TAG, "Context is null");
            String token = GoogleAuthUtil.getToken(mContext, Utils.getLoginEmail(mContext), Constants.URL_SHORTNER_SCOPE);
            Log.d(TAG, "New token is " + token);
            Utils.setAuthToken(mContext, token);
            return response.request().newBuilder()
                    .header("Authorization", "Bearer " + Utils.getAuthToken(mContext))
                    .build();
        } catch (GoogleAuthException e) {
            e.printStackTrace();
            return null;
        }

    }


}
 
開發者ID:jatindhankhar,項目名稱:shorl,代碼行數:25,代碼來源:TokenAuthenticator.java

示例3: authenticate

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
protected String authenticate(Context context, String mGoogleUserName)
		throws IOException, GoogleAuthException,
		GooglePlayServicesAvailabilityException,
		UserRecoverableAuthException {
	// use google auth utils to get oauth2 token
	String scope = "oauth2:https://www.googleapis.com/auth/mapsengine https://picasaweb.google.com/data/";
	String token = null;

	if (mGoogleUserName == null) {
		Log.e(tag, "Google user not set");
		return null;
	}

	token = GoogleAuthUtil.getToken(context, mGoogleUserName, scope);
	return token;
}
 
開發者ID:Last-Mile-Health,項目名稱:ODK-Liberia,代碼行數:17,代碼來源:GoogleMapsEngineTask.java

示例4: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
         * Gets an authentication token from Google and handles any
         * GoogleAuthException that may occur.
         */
        protected String fetchToken() throws IOException {
            try {
                return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
            } catch (UserRecoverableAuthException userRecoverableException) {
                // GooglePlayServices.apk is either old, disabled, or not present
                // so we need to show the user some UI in the activity to recover.
                handleException(userRecoverableException);
            } catch (GoogleAuthException fatalException) {
                // Some other type of unrecoverable exception has occurred.
                // Report and log the error as appropriate for your app.
//                LogHelper.LOGD("GoogleAuthProvider","GetUserNameTask: " + fatalException.getMessage());
//                Toast.makeText(mActivity, fatalException.getMessage(), Toast.LENGTH_SHORT).show();
                if (getAuthCallback() != null) {
                    getAuthCallback().onError(fatalException);
                }
            }
            return null;
        }
 
開發者ID:NaikSoftware,項目名稱:NaikSoftware-Lib-Android,代碼行數:23,代碼來源:GoogleAuthProvider.java

示例5: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Gets an authentication token from Google and handles any
 * GoogleAuthException that may occur.
 */
protected String fetchToken() throws IOException {
    try {
        return GoogleAuthUtil.getToken(MainActivity.this, mEmailText, mScope);
    } catch (UserRecoverableAuthException userRecoverableException) {
        // GooglePlayServices.apk is either old, disabled, or not present
        // so we need to show the user some UI in the activity to recover.
        //mActivity.handleException(userRecoverableException);
    	//Log.e(TAG, userRecoverableException.getMessage(), userRecoverableException);
    	
    	mException = userRecoverableException;
    } catch (GoogleAuthException fatalException) {
        // Some other type of unrecoverable exception has occurred.
        // Report and log the error as appropriate for your app.
    	Log.e(TAG, fatalException.getMessage(), fatalException);
    }
    return null;
}
 
開發者ID:sschendel,項目名稱:SyncManagerAndroid-DemoGoogleTasks,代碼行數:22,代碼來源:MainActivity.java

示例6: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Fetches an access token from the G+ API
 * @return the access token
 * @throws IOException
 */
protected String fetchToken() throws IOException {
    try {
        return GoogleAuthUtil.getToken(
                mContext,
                Plus.AccountApi.getAccountName(mGoogleApiClient),
                "oauth2:" + SCOPES);
    } catch (UserRecoverableAuthException userRecoverableException) {

        // GooglePlayServices.apk is either old, disabled, or not present
        // so we need to show the user some UI in the activity to recover.
        Log.e(TAG, userRecoverableException.toString());
    } catch (GoogleAuthException fatalException) {
        // Some other type of unrecoverable exception has occurred.
        // Report and log the error as appropriate for your app.
        Log.e(TAG, fatalException.toString());
    }
    return null;
}
 
開發者ID:oalami,項目名稱:slidee-android,代碼行數:24,代碼來源:FirebaseService.java

示例7: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Get a authentication token if one is not available. If the error is not
 * recoverable then it displays the error message on parent activity.
 */
private String fetchToken() {
	try {
		String token = GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
		return token;
	} catch (GooglePlayServicesAvailabilityException playEx) {
		// GooglePlayServices.apk is either old, disabled, or not present.
		mActivity.showErrorDialog(playEx.getConnectionStatusCode());
	} catch (UserRecoverableAuthException userRecoverableException) {
		// Unable to authenticate, but the user can fix this.
		// Forward the user to the appropriate activity.
		mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
	} catch (GoogleAuthException fatalException) {
		mActivity.showErrorDialog(ConnectionResult.INTERNAL_ERROR);
	} catch (IOException e) {
		mActivity.showErrorDialog(ConnectionResult.NETWORK_ERROR);
	}
	return null;
}
 
開發者ID:DarrenMowat,項目名稱:PicSync,代碼行數:23,代碼來源:GetTokenTask.java

示例8: DriveSyncService

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public DriveSyncService() throws UserRecoverableAuthException {
    super(SyncService.GoogleDrive);

    try {
        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();

        String token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA);

        if (SettingsUtil.shouldRefreshGDriveToken()) {
            GoogleAuthUtil.clearToken(GlobalApplication.getAppContext(), token);
            token = GoogleAuthUtil.getToken(GlobalApplication.getAppContext(), Settings.getEmail(), "oauth2:" + DriveScopes.DRIVE_APPDATA);
            SettingsUtil.refreshGDriveToken();
        }

        if (BuildConfig.DEBUG)
            LogUtil.log(getClass().getSimpleName(), "Access Token: " + token);

        GoogleCredential credential = new GoogleCredential().setAccessToken(token);
        service = new Drive.Builder(httpTransport, jsonFactory, credential).setApplicationName("Narrate").build();

    } catch (UserRecoverableAuthException ue) {
        throw ue;
    } catch (Exception e) {
        LogUtil.log(getClass().getSimpleName(), "Exception in creation: " + e);
        if (!BuildConfig.DEBUG) Crashlytics.logException(e);
    }

    if (CLEAR_FOLDER_CONTENTS) {
        deleteEverything();
    }
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:33,代碼來源:DriveSyncService.java

示例9: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Gets an authentication token from Google and handles any
 * GoogleAuthException that may occur.
 */
protected String fetchToken() throws IOException {
    String accessToken;
    try {
        accessToken = GoogleAuthUtil.getToken(mActivity, mAccount, mScope);
        GoogleAuthUtil.clearToken (mActivity, accessToken); // used to remove stale tokens.
        accessToken = GoogleAuthUtil.getToken(mActivity, mAccount, mScope);
        return accessToken;
    } catch (UserRecoverableAuthException userRecoverableException) {
        mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
    } catch (GoogleAuthException fatalException) {
        fatalException.printStackTrace();
    }
    return null;
}
 
開發者ID:Truiton,項目名稱:CloudVisionAPI,代碼行數:19,代碼來源:GetTokenTask.java

示例10: onConnected

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
@Override
public void onConnected(Bundle connectionHint) {
    mSignInClicked = false;

    AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String accessToken = null;

            try {
                accessToken = GoogleAuthUtil.getToken(AuthActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient),
                    "oauth2:" + Scopes.PROFILE + " " + Scopes.PLUS_LOGIN + " " + Scopes.PLUS_MOMENTS + " " + Scopes.PLUS_ME);
            } catch (IOException transientEx) {
                transientEx.printStackTrace();
            } catch (UserRecoverableAuthException e) {
                startActivityForResult(e.getIntent(), RC_RECOVER_AUTH);
            } catch (GoogleAuthException authEx) {
                authEx.printStackTrace();
            }

            return accessToken;
        }

        @Override
        protected void onPostExecute(String token) {
            authComplete(token);
        }

    };
    task.execute();
}
 
開發者ID:Redmart,項目名稱:os-mobilizer-android,代碼行數:32,代碼來源:AuthActivity.java

示例11: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
protected String fetchToken() throws IOException {
//        Log.i(TAG, "fetchToken");
        try {
            String tokenn=GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
//            Log.i(TAG, tokenn);
            return tokenn;
        } catch (UserRecoverableAuthException userRecoverableException) {
//            Log.i(TAG, "userRecoverableException");
            mActivity.handleException(userRecoverableException);
        } catch (GoogleAuthException fatalException) {
//            Log.i(TAG, "fatalException");
            fatalException.printStackTrace();
        }
        return null;
    }
 
開發者ID:mohdzeeshanshaikh,項目名稱:Google-Plus-Mini,代碼行數:16,代碼來源:GetUsernameTask.java

示例12: doInBackground

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
@Override
protected String doInBackground(GoogleApiClient... clients) {
    if(clients.length == 0) return null;

    GoogleApiClient client = clients[0];
    String scopes = String.format("oauth2:%s", new Scope(Scopes.PROFILE));

    try {
        return GoogleAuthUtil.getToken(client.getContext(), Plus.AccountApi.getAccountName(client), scopes);
    } catch(Exception exception) {
        return null;
    }
}
 
開發者ID:rapidpro,項目名稱:ureport-android,代碼行數:14,代碼來源:GetGoogleAuthTokenTask.java

示例13: retrieveAuthToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
public String retrieveAuthToken(Account account)
        throws GoogleAuthException, IOException {

    String token = GoogleAuthUtil.getToken(mContext, account, SCOPE);
    // Token needs to be clear so we make sure next time we get a brand new one. Otherwise this
    // may return a token that has already been used by the API and because it's a one time
    // token it won't work.
    GoogleAuthUtil.clearToken(mContext, token);
    return token;
}
 
開發者ID:ribot,項目名稱:ribot-app-android,代碼行數:11,代碼來源:GoogleAuthHelper.java

示例14: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
/**
 * Gets an authentication token from Google and handles any
 * GoogleAuthException that may occur.
 */
protected String fetchToken() throws IOException {
    if ( activity == null )
        return null;
    try {
        logger.debug("Fetching google oauth2 token ...");
        return GoogleAuthUtil.getToken(activity, mEmail, mScope);
    } catch (UserRecoverableAuthException userRecoverableException) {
        // GooglePlayServices.apk is either old, disabled, or not present
        // so we need to show the user some UI in the activity to recover.
        logger.debug("User recoverable error occurred");
        logger.error(userRecoverableException);
        
        // Requesting an authorization code will always throw
          // UserRecoverableAuthException on the first call to GoogleAuthUtil.getToken
          // because the user must consent to offline access to their data.  After
          // consent is granted control is returned to your activity in onActivityResult
          // and the second call to GoogleAuthUtil.getToken will succeed.
        
        activity.startActivityForResult(userRecoverableException.getIntent(), REQUEST_AUTHORIZATION);
    } catch (GoogleAuthException fatalException) {
        logger.warn("google auth error occurred");
        // Some other type of unrecoverable exception has occurred.
        // Report and log the error as appropriate for your app.
        logger.error(fatalException);
    }
    return null;
}
 
開發者ID:edx,項目名稱:edx-app-android,代碼行數:32,代碼來源:GoogleOauth2.java

示例15: getToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入方法依賴的package包/類
private boolean getToken() {
    try{
        token = GoogleAuthUtil.getToken(getActivity().getApplicationContext(), account, AuthActivity.SCOPE);
    }catch (Exception e){
        handleException(e);
        return true;
    }
    return false;
}
 
開發者ID:GhostFlying,項目名稱:PortalWaitingList,代碼行數:10,代碼來源:PortalListFragment.java


注:本文中的com.google.android.gms.auth.GoogleAuthUtil.getToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。