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


Java Credential.setAccessToken方法代碼示例

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


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

示例1: makeClient

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
@Override
public Calendar makeClient(String clientId, String clientSecret,
                           Collection<String> scopes, String applicationName, String refreshToken,
                           String accessToken, String emailAddress, String p12FileName, String user) {

    Credential credential;
    try {
        // if emailAddress and p12FileName values are present, assume Google Service Account
        if (null != emailAddress && !"".equals(emailAddress) && null != p12FileName && !"".equals(p12FileName)) {
            credential = authorizeServiceAccount(emailAddress, p12FileName, scopes, user);
        } else {
            credential = authorize(clientId, clientSecret, scopes);
            if (refreshToken != null && !"".equals(refreshToken)) {
                credential.setRefreshToken(refreshToken);
            }
            if (accessToken != null && !"".equals(accessToken)) {
                credential.setAccessToken(accessToken);
            }
        }
        return new Calendar.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build();
    } catch (Exception e) {
        LOG.error("Could not create Google Drive client.", e);
    }
    return null;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:26,代碼來源:BatchGoogleCalendarClientFactory.java

示例2: makeClient

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
@Override
public Drive makeClient(String clientId, String clientSecret, Collection<String> scopes, String applicationName, String refreshToken, String accessToken) {
    Credential credential;
    try {
        credential = authorize(clientId, clientSecret, scopes);

        if (refreshToken != null && !"".equals(refreshToken)) {
            credential.setRefreshToken(refreshToken);
        } 
        if (accessToken != null && !"".equals(accessToken)) {
            credential.setAccessToken(accessToken);
        }
        return new Drive.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build();
    } catch (Exception e) {
        LOG.error("Could not create Google Drive client.", e);            
    }
    return null;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:BatchGoogleDriveClientFactory.java

示例3: makeClient

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
@Override
public Gmail makeClient(String clientId, String clientSecret, Collection<String> scopes, String applicationName, String refreshToken, String accessToken) {
    Credential credential;
    try {
        credential = authorize(clientId, clientSecret, scopes);

        if (refreshToken != null && !"".equals(refreshToken)) {
            credential.setRefreshToken(refreshToken);
        }
        if (accessToken != null && !"".equals(accessToken)) {
            credential.setAccessToken(accessToken);
        }
        return new Gmail.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build();
    } catch (Exception e) {
        LOG.error("Could not create Google Drive client.", e);
    }
    return null;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:BatchGoogleMailClientFactory.java

示例4: load

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
@Override
public boolean load(String userId, Credential credential) throws IOException {
    Log.i(BnConstants.TAG, "Loading credential for userId ".concat(userId));
    Log.i(BnConstants.TAG, "Loaded access token = ".concat(prefs.getString(userId + ACCESS_TOKEN, "")));

    credential.setAccessToken(prefs.getString(userId + ACCESS_TOKEN, null));

    if (prefs.contains(userId + EXPIRES_IN)) {
        credential.setExpirationTimeMilliseconds(prefs.getLong(userId + EXPIRES_IN,0));
    }
    credential.setRefreshToken(prefs.getString(userId + REFRESH_TOKEN, null));

    return true;
}
 
開發者ID:dementhius,項目名稱:battlenet-oauth2,代碼行數:15,代碼來源:BnSharedPreferencesCredentialStore.java

示例5: authorize

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
public static Credential authorize(String token) {
	Credential ret = new Credential(BearerToken.queryParameterAccessMethod());
	ret.setAccessToken(token);
	return ret;
}
 
開發者ID:Elronnd,項目名稱:ttyrec2video,代碼行數:6,代碼來源:YoutubeUpload.java

示例6: deleteSpreadsheetsRow

import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
/**
 * Deletes Google Spreadsheets row.
 * 
 * @param context the context
 * @param accountName the account name
 * @param trackName the track name
 * @return true if deletion is success.
 */
public static boolean deleteSpreadsheetsRow(
    Context context, String accountName, String trackName) {
  try {
    // Get spreadsheet Id
    List<File> files = searchSpreadsheets(context, accountName);
    if (files == null || files.size() == 0) {
      return false;
    }
    String spreadsheetId = files.get(0).getId();

    // Get spreadsheet service
    SpreadsheetService spreadsheetService = new SpreadsheetService(
        "MyTracks-" + SystemUtils.getMyTracksVersion(context));
    Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod());
    credential.setAccessToken(
        SendToGoogleUtils.getToken(context, accountName, SendToGoogleUtils.SPREADSHEETS_SCOPE));
    spreadsheetService.setOAuth2Credentials(credential);

    // Get work sheet
    WorksheetFeed worksheetFeed = spreadsheetService.getFeed(new URL(
        String.format(Locale.US, SendSpreadsheetsAsyncTask.GET_WORKSHEETS_URI, spreadsheetId)),
        WorksheetFeed.class);
    Iterator<WorksheetEntry> worksheetEntryIterator = worksheetFeed.getEntries().iterator();
    while (worksheetEntryIterator.hasNext()) {
      WorksheetEntry worksheetEntry = (WorksheetEntry) worksheetEntryIterator.next();
      String worksheetTitle = worksheetEntry.getTitle().getPlainText();
      if (worksheetTitle.equals(SPREADSHEETS_WORKSHEET_NAME)) {
        URL url = worksheetEntry.getListFeedUrl();
        Iterator<ListEntry> listEntryIterator = spreadsheetService.getFeed(url, ListFeed.class)
            .getEntries().iterator();
        while (listEntryIterator.hasNext()) {
          ListEntry listEntry = (ListEntry) listEntryIterator.next();
          String name = listEntry.getCustomElements().getValue(SPREADSHEETS_TRANCK_NAME_COLUMN);
          if (name.equals(trackName)) {
            listEntry.delete();
            return true;
          }
        }
      }
    }
  } catch (Exception e) {
    Log.e(TAG, "Unable to delete spreadsheets row.", e);
  }
  return false;
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:54,代碼來源:GoogleUtils.java


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