https://developers.google.com/people/quickstart/python
上記のリンクにアクセスし、Googleアカウントに与えられた手順に従って、プロジェクトを作成します。
OAuthクライアントIDをダウンロードすると、client_secret.jsonが表示されます。
この例ではOAuthクライアントIDは使用されておらず、他のAPIを使用している間は必要になります。あなたはのOAuthクライアントID下回りますサービスアカウントキーをダウンロードする必要が上にaddtionで
。 jsonとしてダウンロードしてください。
サービスアカウントキーへのパスは、次のコードの4行目に記載する必要があります。
コード:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
#scope is necessary if we are accesing gdrive
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('/home/username/Downloads/MyProject.json', scope)
gc = gspread.authorize(credentials)
#to create a new gsheet
sh = gc.create('Sheet_1')
#to open existing gsheet
sh = gc.open('LYKE')
# to share to other users
sh.share('[email protected]', perm_type='user', role='writer')
#to create a worksheet in the gsheet
worksheet = sh.add_worksheet(title='title', rows="500", cols="50")
#Define a cell range and update cells
cell_list = worksheet.range('A1:A10')
for i,cell in enumerate(cell_list):
cell.value=i
worksheet.update_cells(cell_list)
「アクセスGoogleのシートをとPythonとセレンを使用して自動テストでそれを編集しよう」明確にしてください – nithin