, ClientId
이 serviceaccount
생성되었다 client_secret.json 파일에 clientsecret 값없이 serviceaccount 권한을 부여하는 방법. client_secret.json
파일을 다운로드 할 때 ClientId
값만 있고 clientsecret
값이 없습니다. clientsecret
값이 없으면 고객을 어떻게 승인합니까?의 OAuth 2.0 클라이언트 ID와 내가 <code>serviceaccount</code> 자격 증명을 생성 할 때
우리는 console.developers.com에 드롭 다운하고, googleauthorizationflow
를 사용하여 우리의 클라이언트에 권한을 부여 serviceaccount
에 대한 GoogleCredential
객체에 생성 된 액세스 토큰을 전달하고 요청을 만들기 자격 증명을 다시 OAuth 2.0 ClientId
을 생성해야 하는가?
자격 등급 :
public static Credential authorize() throws IOException {
// Load client secrets.
InputStream in = Quickstart.class
.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow =new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline").setApprovalPrompt("auto").build();
Credential credential = new AuthorizationCodeInstalledApp(flow,
new LocalServerReceiver.Builder()
.setHost("localhost").build()).authorize("user");
GoogleCredential gCredential = new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceaccountemail)
.setServiceAccountPrivateKeyFromP12File(new File("privatekeyfile.p12"))
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser(useremail)
.setClientSecrets(clientSecrets)
.build().setAccessToken(credential.getAccessToken())
.setRefreshToken(credential.getRefreshToken())
.setExpirationTimeMilliseconds(
credential.getExpirationTimeMilliseconds());
System.out.println("Credentials saved to " +
DATA_STORE_DIR.getAbsolutePath());
return credential;
}
답장을 보내 주셔서 감사합니다. 도메인을 보유하고 있는데 일부 사용자를 생성하고 일부 약속을 만들었습니다. 이제 서비스 계정을 사용하여 캘린더 정보에 액세스하려면 기존 코드 외에 Quickstart.java의 serviceaccount에 대한 GoogleCredentials를 작성해야합니다. – test
당신은 도메인의 일부 계정에 계정에 서비스 계정 액세스 권한을 부여해야 할 것입니다. – DaImTo
일 것입니다. json 서비스 계정 파일이 아닌 p12 파일을 다운로드 한 것일 수 있습니다. – DaImTo