Last active
January 8, 2016 16:33
-
-
Save richieforeman/7e08b1df0ac4dd7a2d01 to your computer and use it in GitHub Desktop.
Google API Tracing Token - Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// First, Implement an interface to intercept the HTTP Request before it goes out. | |
import java.io.IOException; | |
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; | |
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer; | |
public class TracingTokenInitializer implements GoogleClientRequestInitializer { | |
@Override | |
public void initialize(AbstractGoogleClientRequest<?> req) throws IOException { | |
System.out.println("Attaching tracing token..."); | |
req.put("trace", "token:<<TOKEN GOES HERE>>"); | |
} | |
} | |
// The interceptor must then be attached to Service builder objects before the 'build()' method is ran. | |
// Set the RequestInitailizer by utilizing the 'setGoogleClientRequestInitializer' method. | |
// The same initializer can be utilized for any Apiary-backed service (including: Drive, Directory, etc). | |
public static Reseller getResellerService(GoogleCredential credentials) { | |
GoogleClientRequestInitializer tracingToken = new TracingTokenInitializer(); | |
Reseller service = new Reseller.Builder(HTTP_TRANSPORT, JSON_FACTORY, null) | |
.setApplicationName(ApplicationName) | |
.setHttpRequestInitializer(credentials) | |
.setGoogleClientRequestInitializer(tracingToken).build(); | |
return service; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you receive the token parameter on the endpoint side?