java Google Drive Auth,服务帐户在本地工作,但在应用程序引擎上部署时会中断
我正在编写一个App Engine web应用程序,从Google Drive上的文件夹加载一个图片库。该代码在本地运行时运行正常(图像被正确检索并显示在网页上),但在谷歌应用程序引擎上部署时会中断。具体来说,当启动以下方法时,返回的驱动器服务为null,没有引发异常。凭据(SERVICE_ACCOUNT_EMAIL和PKCS12文件)应该是正确的,因为它们在本地运行代码时有效。我错过了什么?提前谢谢
public static Drive getDriveService() {
HttpTransport httpTransport = new NetHttpTransport();
GsonFactory jsonFactory = new GsonFactory();
GoogleCredential credential;
Drive service = null;
List<String> scopes = Arrays.asList(DriveScopes.DRIVE);
try {
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
service = new Drive.Builder(httpTransport, jsonFactory, null).setApplicationName("MyAppName")
.setHttpRequestInitializer(credential).build();
} catch (Exception e) {
e.printStackTrace();
}
return service;
}
共 (0) 个答案