本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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;
}