如何在 Coldfusion 中将服务帐户与 google 的目录 API 一起使用
How do I use service acct with google's directory API in Coldfusion
我一直在尝试创建一个脚本来将服务帐户与 Google 的目录 API 一起使用,但没有成功。到目前为止我有:
-从 here 下载管理目录 JAR 文件并将它们全部放入我的 WEB-INF/lib 目录
-根据他们的instructions为域委派创建了一个服务帐户——我生成了一个P12文件而不是JSON,因为这是实例化代码使用的
-我将同一指令页面上的 JAVA 代码转换为 ColdFusion,因此它看起来像这样
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();
我的 service=Directory.Init... 行出现 Coldfusion 错误
"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." 我不明白为什么。我所能弄清楚的是,对于其中一个变量似乎是不可接受的值,这是一个相当普遍的错误。
TIA 寻求您能提供的任何帮助
(来自评论...)
可能不相关,但是 .. NetHttpTransport
或 JacksonFactory
均未在 CF 代码中初始化。通常,当您第一次在 un-initialized java object:
上调用方法时,CF 会自动调用 no-arg 构造函数
If you call a public non-static method on the object without first
calling the init method, ColdFusion makes an implicit call to the
default constructor.
但是,我不知道在将未初始化的对象传递给 构造函数 时是否适用相同的规则。尝试在对象上显式调用 init()
以查看是否解决了 NullPointerException:
NetHttpTransport = createObject( "java", "com.google.api.client.http.javanet.NetHttpTransport" ).init();
JacksonFactory = createObject( "java", "com.google.api.client.json.jackson2.JacksonFactory" ).init();
我一直在尝试创建一个脚本来将服务帐户与 Google 的目录 API 一起使用,但没有成功。到目前为止我有:
-从 here 下载管理目录 JAR 文件并将它们全部放入我的 WEB-INF/lib 目录
-根据他们的instructions为域委派创建了一个服务帐户——我生成了一个P12文件而不是JSON,因为这是实例化代码使用的
-我将同一指令页面上的 JAVA 代码转换为 ColdFusion,因此它看起来像这样
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();
我的 service=Directory.Init... 行出现 Coldfusion 错误 "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." 我不明白为什么。我所能弄清楚的是,对于其中一个变量似乎是不可接受的值,这是一个相当普遍的错误。
TIA 寻求您能提供的任何帮助
(来自评论...)
可能不相关,但是 .. NetHttpTransport
或 JacksonFactory
均未在 CF 代码中初始化。通常,当您第一次在 un-initialized java object:
If you call a public non-static method on the object without first calling the init method, ColdFusion makes an implicit call to the default constructor.
但是,我不知道在将未初始化的对象传递给 构造函数 时是否适用相同的规则。尝试在对象上显式调用 init()
以查看是否解决了 NullPointerException:
NetHttpTransport = createObject( "java", "com.google.api.client.http.javanet.NetHttpTransport" ).init();
JacksonFactory = createObject( "java", "com.google.api.client.json.jackson2.JacksonFactory" ).init();