API 및 서비스 > 라이브러리 > 라이브러리 선택 > 사용 버튼 클릭
사용 설정 안해 줄 경우 에러 발생
-> GaxiosError: Access Not Configured. Drive API has not been used in project <프로젝트 번호> before or it is disabled.
-> 라이브러리 > 해당 api > 사용 버튼 클릭 해주면 됌
4-1. 공식 깃헙 샘플 이용
구글에서 제공하는 샘플 프로그램 실행시(node quickstart.js) 에러
-> Error: Cannot find module '...\google-api-nodejs-client\samples\oauth2.keys.json'
--> 해당 경로에 'oauth2.keys.json' 이 파일이 없어서 발생
--> 클라우드 콘솔에서 client id를 받고 다운로드 버튼 클릭시 json 파일 생성해주는데 해당 경로에 복붙해주고 이름 변경해주면 됌
{"web":
{"client_id":"<client_id>",
"project_id":"<project_id>",
"auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"<client_secret>","redirect_uris":["http://localhost:8080/login/oauth2/code/google"]
}
}
4-2. Reference > API > 하단 Try this method 부분 이용
method별로 scope를 다르게 줄 수 있는데 해당 부분 참고하면 좋다.(Authorization 부분)
사용 예시
const auth = await authenticate({
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
scopes: 'https://www.googleapis.com/auth/drive.metadata.readonly',
});
google.options({auth});
순서 참고
Google Workspace에서 개발
Api 키 인증 참고
API 키를 사용하여 인증