Google Admin SDKレポートV1 APIを使用して、Google Apps管理パネルからすべての管理アクティビティを収集しています。Google Admin SDKエラー401の認証時に
私のGoogleのAPI Pythonクライアントは、最近まで私は、次を使用していたバージョン"google-api-python-client (1.5.1)"
に更新されました:
from oauth2client.client import SignedJwtAssertionCredentials
serviceAccountEmail = "[email protected]"
key = "google-apps-file.p12"
scopes = ['https://www.googleapis.com/auth/admin.reports.audit.readonly']
credentials = SignedJwtAssertionCredentials(
serviceAccountEmail, key, scope=scopes, sub=userEmail)
その後、GoogleはSignedJwtAssertionCredentialsのサポートを落としました。だから私はこれに切り替えました。
from oauth2client.service_account import ServiceAccountCredentials
serviceAccountEmail = "[email protected]"
key = "google-apps-file.p12"
scopes = ['https://www.googleapis.com/auth/admin.reports.audit.readonly']
credentials = ServiceAccountCredentials.from_p12_keyfile(
serviceAccountEmail, key, scopes=scopes)`
これは比較的簡単なコード変更であるはずですが、コードを実行すると次のエラーが発生します。
File "/usr/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/googleapiclient/http.py", line 832, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://www.googleapis.com/admin/reports/v1/activity/users/all/applications/admin?alt=json returned "Access denied. You are not authorized to read activity records.">
だから、何の権限は私も気付いています一つのことは、元のコードがsub=userEmail
を求めてさ(偽装するアカウントである、そのアカウントをGoogle Appsドメイン上の特定の管理者権限を持っているでしょう。)、変更されていません
私は401
が得られるはずですが、新しいドキュメントにはsub=userEmail
パラメータの記載がありません。