2017-02-23 6 views
2

gspreadを使ってスプレッドシートを作成しました。gspreadで作成したgoogleスプレッドシート

Googleのサービスキーアカウントで作成されたもので、どのようにアクセスできるのかわかりません。

特定のサービスキーで作成されたすべてのスプレッドシートを確認するにはどうすればよいですか?

https://github.com/burnash/gspread

+0

あなたはこのために 'openallを()'を使用することができます:http://gspread.readthedocs。 io/en/latest /#gspread.Client.openall – Burnash

答えて

2

は最後に答えを見つけました。

gspreadコード内で直接見た後、私はこれが見つかりました:だから、この作品https://github.com/burnash/gspread/blob/addd4940bf7e4f87aae598920facae2155e555b6/gspread/client.py#L151

を:

from oauth2client.service_account import ServiceAccountCredentials 
import gspread 
from gspread.ns import _ns 

# If modifying these scopes, delete your previously saved credentials 
# at ~/.credentials/sheets.googleapis.com-python-quickstart.json 
SCOPES = ['https://spreadsheets.google.com/feeds', 
      'https://www.googleapis.com/auth/drive'] 
CLIENT_SECRET_FILE = 'client_secret.json' 
APPLICATION_NAME = 'Google Sheets API Python' 


def get_credentials(): 
    """Gets valid user credentials from storage. 

    If nothing has been stored, or if the stored credentials are invalid, 
    the OAuth2 flow is completed to obtain the new credentials. 

    Returns: 
     Credentials, the obtained credential. 
    """ 

    return ServiceAccountCredentials.from_json_keyfile_name(CLIENT_SECRET_FILE, SCOPES) 

credentials = get_credentials() 
gc = gspread.authorize(credentials) 
feed = gc.get_spreadsheets_feed() 

for elem in feed.findall(_ns('entry')): 
    elem_title = elem.find(_ns('title')).text 
    print(elem_title) 
関連する問題