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


Java Key類代碼示例

本文整理匯總了Java中com.google.api.client.util.Key的典型用法代碼示例。如果您正苦於以下問題:Java Key類的具體用法?Java Key怎麽用?Java Key使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Key類屬於com.google.api.client.util包,在下文中一共展示了Key類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTokenFromCode

import com.google.api.client.util.Key; //導入依賴的package包/類
private void getTokenFromCode(final String code) throws IOException {

        log.debug("Fetching authorisation token using authorisation code");
        HttpRequest request =
                HTTP_TRANSPORT.createRequestFactory().buildGetRequest(new GenericUrl("https://login.live.com/oauth20_token.srf") {
                    @Key("client_id")
                    private String id = clientId;
                    @Key("client_secret")
                    private String secret = clientSecret;
                    @Key("code")
                    private String authCode = code;
                    @Key("grant_type")
                    private String grantType = "authorization_code";
                    @Key("redirect_uri")
                    private String redirect = "https://login.live.com/oauth20_desktop.srf";
                });

        request.setParser(new JsonObjectParser(JSON_FACTORY));

        processResponse(request.execute());
    }
 
開發者ID:wooti,項目名稱:onedrive-java-client,代碼行數:22,代碼來源:OneDriveAuthorisationProvider.java

示例2: getTokenFromRefreshToken

import com.google.api.client.util.Key; //導入依賴的package包/類
private void getTokenFromRefreshToken(final String refreshToken) throws IOException {

        log.debug("Fetching authorisation token using refresh token");

        HttpRequest request =
                HTTP_TRANSPORT.createRequestFactory().buildGetRequest(new GenericUrl("https://login.live.com/oauth20_token.srf") {
                    @Key("client_id")
                    private String id = clientId;
                    @Key("client_secret")
                    private String secret = clientSecret;
                    @Key("refresh_token")
                    private String token = refreshToken;
                    @Key("grant_type")
                    private String grantType = "refresh_token";
                    @Key("redirect_uri")
                    private String redirect = "https://login.live.com/oauth20_desktop.srf";
                });

        request.setParser(new JsonObjectParser(JSON_FACTORY));

        processResponse(request.execute());
    }
 
開發者ID:wooti,項目名稱:onedrive-java-client,代碼行數:23,代碼來源:OneDriveAuthorisationProvider.java

示例3: getFields

import com.google.api.client.util.Key; //導入依賴的package包/類
private java.util.List<Field> getFields(){
    if (fields != null) return fields;

    fields = new ArrayList<Field>();

    for(Field field : getClass().getDeclaredFields() ){
        Key keyAnnotation = field.getAnnotation(Key.class);
        if ( keyAnnotation != null ) fields.add(field);
    }

    return fields;
}
 
開發者ID:prashant31191,項目名稱:meets-android,代碼行數:13,代碼來源:Serializable.java

示例4: savePreferences

import com.google.api.client.util.Key; //導入依賴的package包/類
/**
 * Saves user preferences
 *
 * @param audioBoxClient the client
 *
 * @return true if operation succeed throws an exception if something goes wrong
 *
 * @throws fm.audiobox.core.exceptions.AudioBoxException if any of the remote error exception is detected.
 * @throws java.io.IOException                           if any connection problem occurs.
 * @see fm.audiobox.core.exceptions.AudioBoxException
 */
public boolean savePreferences(AudioBoxClient audioBoxClient) throws IOException {

  // 'api/v1/preference.json' endpoint accepts a user object that inherit
  // Preferences.class fields like this:
  //
  // {"user"=>{"prebuffer"=>"1", "accept_emails"=>"0", "js_demuxer"=>"1"}}
  //
  // This is why we need a custom crafted JSON and that's why we create a map.

  Map<String, Object> prefs = new HashMap<>();

  // Since preferences are an open set of fields that may
  // vary in space and time (:D) and we don't want to
  // update a map each time a preference is added or removed,
  // we proceed with reflection. This may reduce maintenance
  // hassles.
  Field[] fs = getPreferences().getClass().getDeclaredFields();

  for (Field f : fs ){

    // @Key annotated fields are the fields that we want to keep in sync
    if (f.isAnnotationPresent( Key.class ) ) {
      try {

        Object value = f.get( getPreferences() );

        // Drop null values
        if (value == null) {
          continue;
        }

        // Boolean values are transformed into 1 and 0 strings
        // because of some technical issue with the backend.
        if (f.getType() == boolean.class) {
          value = (Boolean) value ? "1" : "0";
        }

        prefs.put( f.getName(), value.toString() );

      } catch ( IllegalAccessException e ) {

        // Erroneous or problematic fields are just discarded,
        // but we don't want to abort the request, thus we catch
        // the exception and keep it going.
        log.error( "Preference field is not readable due to some unsupported state: " + e.getMessage() );
      }
    }
  }

  Map<String, Object> u = new HashMap<>();
  u.put("user", prefs);

  audioBoxClient.doPUT( Preferences.PATH, new JsonHttpContent( audioBoxClient.getConf().getJsonFactory(), u ) );
  return true;
}
 
開發者ID:icoretech,項目名稱:audiobox-jlib,代碼行數:67,代碼來源:User.java


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