2016-08-12 5 views
1

API 콘솔에서 [email protected] 이하로 프로젝트를 만들었으며 Analytics APISearch Console API 서비스에 대한 서비스 계정을 성공적으로 사용하고 있습니다. 나는 지금 Gmail V1 API를 사용하도록 설정하고이 코드를 실행했습니다서비스 계정이 포함 된 Gmail API

gmail_scopes = [ 
    "https://mail.google.com/", 
    "https://www.googleapis.com/auth/gmail.compose", 
    "https://www.googleapis.com/auth/gmail.readonly", 
    "https://www.googleapis.com/auth/gmail.send", 
    "https://www.googleapis.com/auth/gmail.readonly" 
] 
gmail = Google::Apis::GmailV1::GmailService.new 
gmail.authorization = Google::Auth.get_application_default(gmail_scopes) 

이 내가 웹 로그 분석에 권한을 부여하고 콘솔 API를 검색하는 데 사용하는 (물론 다른 범위와) 같은 코드입니다.

나는이 프로그램을 실행할 때 나는 BAD REQUESTFailed Precondition 오류를 얻을 그러나 :

API가 initiatlization에 그를 serviceaccount 이메일 주소에 대한 존재하지 않는받은 편지함에 액세스를 시도하고 있기 때문에 일부 인터넷 검색이 나를 그에게 말한다
gmail.get_user_profile("[email protected]") 

입니다 process [email protected]을 포함시켜야 API 서비스가 해당받은 편지함을 사용할 수 있습니다.

어떻게하면됩니까?

나는 다음을 시도했다 '...'항상 이메일 주소를 @ gmail.com 사서함에 액세스 할 수 없습니다

gmail.authorization = Google::Auth.get_application_default(gmail_scopes, username: '...') 
gmail.authorization = Google::Auth.get_application_default(gmail_scopes, {username: '...'}) 
gmail.authorization.username = '...' 

답변

1

서비스 계정 서비스를 제공합니다. OAuth2 UserAuthorizer를 사용해야합니다. 예를 들어 Gmail API Ruby Quickstart guide을 참조하십시오.

관련 문제