public class CommonGoogleClientRequestInitializer extends Object implements GoogleClientRequestInitializer
The simplest usage is to use it to set the key parameter:
public static final GoogleClientRequestInitializer KEY_INITIALIZER =
new CommonGoogleClientRequestInitializer(KEY);
There is also a constructor to set both the key and userIp parameters:
public static final GoogleClientRequestInitializer INITIALIZER =
new CommonGoogleClientRequestInitializer(KEY, USER_IP);
If you want to implement custom logic, extend it like this:
public static class MyRequestInitializer extends CommonGoogleClientRequestInitializer {
@Override
public void initialize(AbstractGoogleClientRequest <? > request)
throws IOException {
// custom logic
}
}
Finally, to set the key and userIp parameters and insert custom logic, extend it like this:
public static class MyRequestInitializer2 extends CommonGoogleClientRequestInitializer {
public MyRequestInitializer2() {
super(KEY, USER_IP);
}
@Override
public void initialize(AbstractGoogleClientRequest <? > request)
throws IOException {
super.initialize(request); // must be called to set the key and userIp parameters
// insert some additional logic
}
}
Subclasses should be thread-safe.
| Constructor and Description |
|---|
CommonGoogleClientRequestInitializer() |
CommonGoogleClientRequestInitializer(String key) |
CommonGoogleClientRequestInitializer(String key,
String userIp) |
| Modifier and Type | Method and Description |
|---|---|
String |
getKey()
Returns the API key or
null to leave it unchanged. |
String |
getUserIp()
Returns the user IP or
null to leave it unchanged. |
void |
initialize(AbstractGoogleClientRequest<?> request)
Subclasses should call super implementation in order to set the key and userIp.
|
public CommonGoogleClientRequestInitializer()
public CommonGoogleClientRequestInitializer(String key)
key - API key or null to leave it unchangedpublic void initialize(AbstractGoogleClientRequest<?> request) throws IOException
initialize in interface GoogleClientRequestInitializerIOException - I/O exceptionpublic final String getKey()
null to leave it unchanged.public final String getUserIp()
null to leave it unchanged.Copyright © 2010–2019 Google. All rights reserved.