私はスプレッドシートを取得するためにPython2.7でGspreadを使用しようとしています。私はログインできるようですが、コマンドを発行するたびにGspread - スプレッドシートを取得できません
gc.openall()
ただ空リストを返します。私はすべてのサービスアカウントの管理者アクセス権を与えており、シートAPIはGoogleコンソールで有効になっています。誰かが私が間違っていることを指摘できますか?以下は
私name-hash.json
ファイルGoogleが返され、ログインするために使用されます。
{
"type": "service_account",
"project_id": "name-id",
"private_key_id": "PRIVATE KEY ID",
"private_key": "-----BEGIN PRIVATE KEY-----
...
\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "CLIENTID",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-279%40name-id.iam.gserviceaccount.com"
}
私のコードは次のとおりです。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
def login(json_key):
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_key, scope)
gc = gspread.authorize(credentials)
return gc
gc = login('/Users/username/Downloads/name-hash.json')
files = gc.openall()
print(files)
[]
Googleドライブのルートにあるシートですか?それはgspreadが動作するためのものです。最新のv4 google apiを直接使用するコードを使用してgspreadを書き直しました。私は強くそれをお勧めします。それはかなり急な学習曲線を持っていますが、十分な価値があります! – Sebastien
私はスプレッドシート自体をアドレスと共有することができないと思う:[email protected] open_by_keyを特定のスプレッドシートで試してみると、エラーメッセージが表示される – Sebastien