別のドメインを設定せずに、Python を使用してGoogleカレンダーのリクエストを設定したいと考えています。 https://developers.google.com/google-apps/calendar/quickstart/python: GoogleカレンダーのウォッチリクエストにPythonを使用する
- は、私は次の例は、APIクライアントをインポートし、正常に認証資格情報を取得することができます。
その後、私はカレンダーサービスを設定しました。問題のないイベントの一覧表示、挿入、削除が可能です。
私が抱いている問題は、ウォッチリクエストを実行して、私がpython内からウェブフックを持っているときです。 エラーを受け取りました: "googleapiclient.errors.HttpError:https://www.googleapis.com/calendar/v3/calendars/primary/events/watch?alt=json returned" WebHookコールバックはHTTPSでなければなりません: ">
明らかに私はカレンダーが私がそれを与えているwebhookに満足するように設定する必要があるものがありません。 これは、httpsで別のドメインを設定することなく、python内から行うことは可能ですか?
最小作業例:watch requestsのドキュメントで
import httplib2
import os
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
import uuid
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Calendar API'
def get_credentials():
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-api.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else:
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
def main():
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
## TESTING callback receiver:
eventcollect = {
'id': str(uuid.uuid1()),
'type': "web_hook"
}
service.events().watch(calendarId='primary', body=eventcollect).execute()
if __name__ == '__main__':
main()
ありがとう、私は理解しています。私はwatch()にポストされたJSON変数で指すWebHookとして十分なURLを持つローカルホストとして自己署名のhttpsを設定できるかどうか疑問に思っていました。 – Jonathan
を見てください:https://ngrok.com/ – hybor
ポインタありがとう! – Jonathan