簡體   English   中英

如何使用 SlidesSnippet 工具可能用於 google slides api python

[英]How to use SlidesSnippet tool probably for google slides api python

所以我正在嘗試使用 SlidesSnippets 自動創建谷歌幻燈片

https://github.com/gsuitedevs/python-samples/blob/master/slides/snippets/slides_snippets.py

我擁有所有 api 憑據句柄並可以訪問我的 api 服務,但很難理解如何將代碼與我的幻燈片目錄完全鏈接

( https://docs.google.com/presentation/u/0/?tgif=d )

我把github中的代碼重新寫了下, init部分如下所示:

 class SlidesSnippets(object): # def __init__(self, service, drive_service, sheets_service, credentials): def __init__(self): # self.credentials = credentials self.credentials = GoogleCredentials.get_application_default() scope = [ 'https://www.googleapis.com/auth/drive', ] self.credentials_scoped = self.credentials.create_scoped(scope) http = self.credentials_scoped.authorize(httplib2.Http()) # self.service = service self.service = build('slides', 'v1', http=http) # self.drive_service = drive_service self.drive_service = build('drive', 'v3', http=http) # self.sheets_service = sheets_service

注釋是最初在類函數中的內容,然后我用我的詳細信息替換了它。

所以當我運行這段代碼時:

 import slides_snippets as slides slides_init = slides.SlidesSnippets() slides_dict = slides_init.create_presentation("TEST")

我得到這個看起來像幻燈片 id 標簽的響應,然后當我去

當我嘗試進入帶有標簽的目錄時

( https://docs.google.com/presentation/d/ OUTPUT_SLIDE_ID_FROM_create_presentation /edit)

它要求我請求控制,並且在我的幻燈片驅動器中無處可見。

我在 SlidesSnippets init函數中搞砸了什么嗎?

我使用了一些函數來初始化它。 也許它可以幫助你。

class SlidesSnippets(object): def init (self): self.drive_credentials = None self.slides_credentials = None

def drive_service(self,gdrive_SCOPES = ['https://www.googleapis.com/auth/drive.file']):
    '''gdriver token'''
    if os.path.exists('drivetoken.pickle'):
        with open('drivetoken.pickle', 'rb') as token:
            gdrive_creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not gdrive_creds or not gdrive_creds.valid:
        if gdrive_creds and gdrive_creds.expired and gdrive_creds.refresh_token:
            gdrive_creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', gdrive_SCOPES)
            gdrive_creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('drivetoken.pickle', 'wb') as token:
            pickle.dump(gdrive_creds, token)

    drive_service = build('drive', 'v3', credentials=gdrive_creds)
    self.drive_service,self.drive_credentials = drive_service, gdrive_creds
    return self.drive_service,self.drive_credentials

def slides_service(self,slides_SCOPES = ['https://www.googleapis.com/auth/presentations']):
    '''slides token'''
    if os.path.exists('slidetoken.pickle'):
        with open('slidetoken.pickle', 'rb') as token:
            slides_creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not slides_creds or not slides_creds.valid:
        if slides_creds and slides_creds.expired and slides_creds.refresh_token:
            slides_creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', slides_SCOPES)
            slides_creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('slidetoken.pickle', 'wb') as token:
            pickle.dump(slides_creds, token)

    slides_service = build('slides', 'v1', credentials=slides_creds)
    self.slides_service,self.slides_credentials = slides_service, slides_creds
    return self.slides_service,self.slides_credentials

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM