Pythonを使用して(別のドメインを設定せずに)Googleカレンダーの監視リクエストを設定したい。
API クライアントをインポートし、https : //developers.google.com/google-apps/calendar/quickstart/pythonの例に従って、認証された資格情報を正常に取得できます。
次に、カレンダー サービスを設定すると、問題なくイベントを一覧表示、挿入、および削除できます。
私が抱えている問題は、ウォッチ リクエストを実行して、Python 内から Webhook を取得するときです。次のエラーが表示されます: 「googleapiclient.errors.HttpError: https://www.googleapis.com/calendar/v3/calendars/primary/events/watch?alt=json が「WebHook コールバックは HTTPS である必要があります:">」
明らかに、カレンダーが私が提供している Webhook に満足するように設定する必要のある何かが欠けています。https を使用して別のドメインを設定せずに、Python 内からこれを行うことは可能ですか?
最小動作例:
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()
ウォッチリクエストのドキュメントに、Required Properties
一部あります。この部分では、次のことが明確に述べられています。
address
URLへのプロパティ文字列を設定することを、この通知チャネルの通知をリッスンし、応答します。これは Webhook コールバック URL であり、HTTPS を使用する必要があります。申し訳ありませんが、これに対する回避策はないと思います。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加