Python googledriveapi和rasa问题
我在执行此活动时遇到了一个奇怪的问题,此活动已发布在此处: 我用以下代码解决了这个问题:Python googledriveapi和rasa问题,python,google-drive-api,rasa,Python,Google Drive Api,Rasa,我在执行此活动时遇到了一个奇怪的问题,此活动已发布在此处: 我用以下代码解决了这个问题: class ActionQuestion(Action): # def name(self) -> Text: return "action_question" def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: D
class ActionQuestion(Action):
#
def name(self) -> Text:
return "action_question"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import logging
logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('drive', 'v3', credentials=creds)
# Call the Drive v3 API
page_token = None
while True:
response = service.files().list(q="name='Getting Started'",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
for file in response.get('files', []):
# Process change
dispatcher.utter_message('Found file: %s please visit the link https://drive.google.com/open?id=%s' % (file.get('name'), file.get('id')))
dispatcher.utter_message(type(question))
page_token = response.get('nextPageToken', None)
if page_token is None:
break
return []
我的问题是,不是直接在以下行中传递文件名:
response = service.files().list(q="name='Getting Started'",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
我使用tracker.get_slot方法传递文件名,如下所示:
question = tracker.get_slot("document")
response = service.files().list(q="name=question",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
我收到以下http错误:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?**q=name+%3D+question**&spaces=drive&fields=nextPageToken%2C+files%28id%2C+name%29&alt=json returned "Invalid Value">
如何在请求url中正确传递此插槽?url突出显示了查询文本以显示请求的url。
response = service.files().list(q='(name contains \'{0}\')'.format(a),
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
如果您可以提供有关解决方案的一些详细信息,然后将其标记为解决方案,这将有助于将来的堆栈溢出访问者=)
response = service.files().list(q='(name contains \'{0}\')'.format(a),
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()