I have been trying to create a script to use a service acct with Google's Directory API and having no luck. So far I have:
-Downloaded the Admin Directory JAR Files from here and put them all in my WEB-INF/lib dir
-Created a service acct according to their instructions for domain delegation – I generated a P12 file instead of JSON because that's what the instantiation code uses
-I converted the JAVA code on that same instruction page to ColdFusion so it looks like this
p12File = createObject( 'java', 'java.io.File' ).init("{my file path}");
accountId = JavaCast( "string", "XXX@XXX.iam.gserviceaccount.com" );
GoogleCredential = createObject( "java", "com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder" );
HttpTransport = createObject( "java", "com.google.api.client.http.HttpTransport" );
NetHttpTransport = createObject( "java", "com.google.api.client.http.javanet.NetHttpTransport" );
JsonFactory = createObject( "java", "com.google.api.client.json.JsonFactory" );
JacksonFactory = createObject( "java", "com.google.api.client.json.jackson2.JacksonFactory" );
Directory = createObject( "java", "com.google.api.services.admin.directory.Directory$Builder" );
DirectoryScopes = createObject( "java", "com.google.api.services.admin.directory.DirectoryScopes" );
Collections = createObject( "java", "java.util.Collections" );
credential = GoogleCredential
.setTransport( NetHttpTransport )
.setJsonFactory( JacksonFactory )
.setServiceAccountId( accountId )
.setServiceAccountScopes( Collections.singleton( DirectoryScopes.ADMIN_DIRECTORY_USER ) )
.setServiceAccountUser("XXX@XXX.org")
.setServiceAccountPrivateKeyFromP12File( p12File )
.build();
service = Directory.Init( NetHttpTransport, JacksonFactory, javaCast( "null", "" ) ).setHttpRequestInitializer( credential ).build();
I get a Coldfusion Error at my service=Directory.Init... line that reads "The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values." and I don't understand why. All I've been able to figure out is that this is a rather generic error for what appears to be an unacceptable value for one of the variables.
TIA for any help you could offer