2017-07-19 110 views

回答

0

您可以了解这Creating a service account

采取记下服务帐户的电子邮件地址和服务 帐户的P12私钥文件存储到您的 应用程序访问的位置。您的应用程序需要他们进行授权的API调用。

所以,它取决于你把它放在你的项目文件夹。但是之后你必须指定路径。在代码中使用p12的演示。

GoogleCredential credential = new GoogleCredential.Builder() 
    .setTransport(httpTransport) 
    .setJsonFactory(JSON_FACTORY) 
    .setServiceAccountId(emailAddress) 
    .setServiceAccountPrivateKeyFromP12File(new File("MyProject.p12")) 
    .setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN)) 
    .setServiceAccountUser("[email protected]") 
    .build();