지난 달에 저는 Google 관리자가 회사 도메인 내에서 Google 자원을 관리하기 위해 다양한 Google API를 광범위하게 사용하는 Python GAE 응용 프로그램 작업을 마쳤습니다. 앱이 끝났습니다 !!!하지만 이번 달 Google은 현재 구현중인 EmailSettings API가 더 이상 지원되지 않으며 이메일 설정이 Gmail API로 이전 될 것이라고 발표했습니다. 지금까지 일부 설정 (즉, 별칭, 전달, 부재중 응답 및 서명)을 마이그레이션했습니다. Google의 마이그레이션 문서에서 두 API 간의 주요 차이점과 마이그레이션 방법에 대한 다소 모호한 언급을 지적합니다. 어쨌든, 현재 서비스 계정을 사용하여 send-as 설정을 수정하기 위해 새 API를 구현하려고합니다. 여기에 내가 서비스 계정에 대한 서비스 (다시, 이것이 파이썬) 만드는 오전 방법은 다음과 같습니다, 내가 AutoForwarding 설정을 업데이트하려고이 특정 예에서Gmail 설정 API 백엔드 오류 - Python
scopes = ['https://mail.google.com/', 'https://www.googleapis.com/auth/gmail.settings.basic', 'https://www.googleapis.com/auth/gmail.settings.sharing']
email = "[email protected]"
credentials = oauth2.service_account.build_credentials(scope=scopes, user=me)
http = httplib2.Http()
credentials.authorize(http)
service = google_api_helper.build("gmail", "v1", credentials)
body = {'emailAddress':'[email protected]'}
service_2.users().settings().updateAutoForwarding(userId="me", body=body).execute()
을하지만, 몇 가지 같은 시나리오 및 오류입니다 send-as 설정. 내가 겪고있는 문제는 다음과 같습니다. Google에서 "섬세한 설정"을 사용하려면 범위를 사용해야합니다. 'https://www.googleapis.com/auth/gmail.settings.sharing'은 작동하도록 서비스 계정을 만들어야합니다.
내가 서비스 계정에 도메인 전체 액세스를 인증하고 있다면이 오류를 얻고있다 왜HttpError: https://www.googleapis.com/gmail/v1/users/me/settings/autoForwarding?alt=json returned "Backend Error">
이이 API입니다 : 내가 비록 그것을 사용하려고 할 때마다
, 난 500 오류 메시지가 오류 또는 현재 oauth2 인증을 구현하는 방식입니까? 업데이트 된 oauth2client 라이브러리를 사용하여 로컬 JSON 파일을 통해
credentials = GoogleCredentials.get_application_default()
httpauth = credentials.authorize(Http())
service = build("gmail", "v1", http=http_auth)
aliases_2 = service.users().settings().sendAs().list(userId="[email protected]").execute()
:
credentials_new = ServiceAccountCredentials.from_json_keyfile_name("app/service_account_key.json", scopes)
delegated_credentials = credentials_new.create_delegated(sub="[email protected]")
http_auth = delegated_credentials.authorize(Http())
service = build("gmail", "v1", http=http_auth)
오래된 oauth2client 라이브러리를 사용하고 사용
응용 프로그램 기본 인증을 사용하여 : 내가 성공하지 않고 여러 가지 구현을 시도했다 새 라이브러리 구현에서 더 이상 지원되지 않는 SignedJwtAssertionCredentials 함수 :
credentials = SignedJwtAssertionCredentials(str(settings['oauth2_service_account']['client_email']).encode('utf-8'), settings['oauth2_service_account']['private_key'], scope=scopes, sub="[email protected]")
auth2token = OAuth2TokenFromCredentials(credentials)
# With this implementation i was able to provide the google admin account which is supposed to have super admin access to the "sub" parameter, this used to work for the EmailSettings API, but for this new implementation you need to pass the email of the user you are trying to gain access to.
# build service
# call API
모든 세 가지 구현을 통해 기본 범위를 호출 할 수 있었지만 settings.sharing 범위의 모든 설정을 변경하려고 할 때마다 백엔드 오류 메시지가 나타났습니다. 이것은 나를 미치게하고 나는 방금이 응용 프로그램을 마쳤다 !!!! 아이디어가 있거나 이전에이 문제에 부딪혔 으면 알려주세요 !!!!! ...
에릭, 답장을 보내 주셔서 감사합니다. 나는 3 가지 인증 방법을 시도한 이후로 많이 생각했습니다. 나는이 문제를 자세히 들여다 보겠다. 포워딩 업데이트에 대해서만 언급하고 있지만 실제로는 'https://www.googleapis.com/auth'의 범위에있는 모든 서비스/리소스에서 발생한다. /gmail.settings.sharing; 이 작업을 수행하는 팀원 일 경우 해당 특정 범위 아래의 리소스를 확인하십시오. 하지만 다시 직접적인 문제는 인증 문제입니다 ... 바라건대 해결책은 곧 있습니다. – John
이 문제를 해결해야하는 수정 프로그램이 어제 출시되었습니다.참고 : gmail.settings.sharing 범위가 필요한 메소드를 사용하려면 서비스 계정과 함께 도메인 전체 위임을 사용해야합니다. –
Eric, 수정본을 배포 한 후 신속하게 응답 해 주셔서 감사합니다 !!! 그 범위에 해당하는 기능을 구현하고 다른 관련 문제가있는 경우 알려주도록하겠습니다. 물론, 우리는 이미 이러한 요구 사항 (즉 도메인 전체 위임 서비스 계정)을 준수하지만 헤드 업에 다시 한 번 감사드립니다. – John