クライアント ライブラリの PHP バージョンを使用して認証資格情報を作成し、それをデータベースに保存します。Python で同じ資格情報を使用するスクリプトを作成したいと思います。client.Credentials.new_from_json() を使用してみましたが、保存するものがそのメソッドに必要なすべてではないことに気付きました。
そのため、最初に (PHP から取得したときに) データを別の方法で保存する必要があるかどうか、または現在保存している認証トークンのみを使用して別のメソッドで Credentials オブジェクトを作成できるかどうかについてのアドバイスを探しています。
わかりやすくするために、現在保存しているものは次のとおりです。
{" access_token":"ここに文字列","token_type":"Bearer","expires_in":3600,"id_token":"ここに文字列","refresh_token":"ここに文字列"}
アドバイスをありがとう!
編集:
これをハッキングして、次のコードで動作させました。これが良い解決策ではないことは明らかだと思いますが、正しい軌道に乗っていることを確認したかっただけで、何らかの方法で適切に形成された Credentials オブジェクトを取得したら、理論的にはすべてが機能します。
secrets = [the contents of client_secrets.json]
creds = '{"access_token":"string here","token_type":"Bearer","expires_in":3600,"id_token":"string here","refresh_token":"string here"}'
creds_dict = json.loads(creds)
creds_dict['_module'] = "oauth2client.client"
creds_dict['_class'] = "OAuth2Credentials"
creds_dict['client_id'] = secrets['installed']['client_id']
creds_dict['client_secret'] = secrets['installed']['client_secret']
#this is a date a la "2013-09-23T06:13:04Z" in a real to_json formed Credentials object
creds_dict['token_expiry'] = 'none'
creds_dict['token_uri'] = 'https://accounts.google.com/o/oauth2/token'
creds_dict['user_agent'] = None
creds_dict['invalid'] = False
creds_final = json.dumps(creds_dict)
return creds_final