Skip to content

Instantly share code, notes, and snippets.

@richieforeman
Last active January 8, 2016 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richieforeman/7e08b1df0ac4dd7a2d01 to your computer and use it in GitHub Desktop.
Save richieforeman/7e08b1df0ac4dd7a2d01 to your computer and use it in GitHub Desktop.
Google API Tracing Token - Java
//// 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;
}
@avillarrealruenes
Copy link

How do you receive the token parameter on the endpoint side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment