2017-04-19 12 views
0

別のドメインを設定せずに、Python を使用してGoogleカレンダーのリクエストを設定したいと考えています。 https://developers.google.com/google-apps/calendar/quickstart/pythonGoogleカレンダーのウォッチリクエストにPythonを使用する

  1. は、私は次の例は、APIクライアントをインポートし、正常に認証資格情報を取得することができます。

  2. その後、私はカレンダーサービスを設定しました。問題のないイベントの一覧表示、挿入、削除が可能です。

私が抱いている問題は、ウォッチリクエストを実行して、私が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() 

答えて

0

は、Required Properties部分があります。この部分では、それが明確に記載されている:

  • リッスンし、この通知チャネルの通知に応答URLに設定addressプロパティ文字列。 これはWebhookのコールバックURLであり、HTTPSを使用する必要があります。

私は申し訳ありませんが、これには回避策がないと思います。

+0

ありがとう、私は理解しています。私はwatch()にポストされたJSON変数で指すWebHookとして十分なURLを持つローカルホストとして自己署名のhttpsを設定できるかどうか疑問に思っていました。 – Jonathan

+0

を見てください:https://ngrok.com/ – hybor

+0

ポインタありがとう! – Jonathan

関連する問題