2

指定された2つの日付の間にGoogleカレンダーのすべての空き時間情報を取得したいと思います。freebusyオブジェクトのドキュメントに従っています。

基本的に、2つの日付を選択できるフォームを持つindex.htmlがあります。それらの日付をアプリケーションに送信します(Python Google AppEngineがサポートされています)。

これは、読みやすくするために簡略化されたコードです。

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

decorator = oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope='https://www.googleapis.com/auth/calendar',
    message=MISSING_CLIENT_SECRETS_MESSAGE)

service = build('calendar', 'v3')

class MainPage(webapp2.RequestHandler):
  @decorator.oauth_required
  def get(self):
    # index.html contains a form that calls my_form
    template = jinja_enviroment.get_template("index.html")
    self.response.out.write(template.render())

class MyRequestHandler(webapp2.RequestHandler):
  @decorator.oauth_aware
  def post(self):
    if decorator.has_credentials():

      # time_min and time_max are fetched from form, and processed to make them
      # rfc3339 compliant
      time_min = some_process(self.request.get(time_min))
      time_max = some_process(self.request.get(time_max))

      # Construct freebusy query request's body
      freebusy_query = {
        "timeMin" : time_min,
        "timeMax" : time_max,
        "items" :[
          {
            "id" : my_calendar_id
          }
        ]
      }

      http = decorator.http()
      request = service.freebusy().query(freebusy_query)
      result = request.execute(http=http)
    else:
      # raise error: no user credentials

app = webapp2.WSGIApplication([
    ('/', MainPage),     
    ('/my_form', MyRequestHandler),
    (decorator.callback_path, decorator.callback_handler())
], debug=True)

しかし、freebusy呼び出し(スタックトレースの興味深い部分)でこのエラーが発生します:

File "/Users/jorge/myapp/oauth2client/appengine.py", line 526, in setup_oauth
    return method(request_handler, *args, **kwargs)
  File "/Users/jorge/myapp/myapp.py", line 204, in post
    request = service.freebusy().query(freebusy_query)
  TypeError: method() takes exactly 1 argument (2 given)

いくつかの調査を行いましたが、カレンダーv3とPythonでのfreebusy呼び出しを使用した実行例は見つかりませんでした。APIエクスプローラーで呼び出しを正常に実行しました。

エラーを理解した場合、oauth_awareデコレータは、その制御下にあるコードのすべての呼び出しを何らかの方法でフィルタリングしているようです。呼び出し可能オブジェクトがOAuthDecorator.oauth_awareoauth2clientのメソッドに渡されます。そして、この呼び出し可能オブジェクトはwebapp2.RequestHandlerのインスタンスです。のようにMyRequestHandler

ユーザーが適切にログに記録されている場合、oauth_awareメソッドは、を呼び出すことにより、目的のメソッドへの呼び出しを返しますmethod(request_handler, *args, **kwargs)。そして、ここにエラーがあります。、許可されているよりも多くの引数を取っているためTypeErrorです。method

それが私の解釈ですが、私が正しいかどうかはわかりません。freebusy().query()他の方法で電話する必要がありますか?私の分析のどの部分も本当に意味がありますか?私はこれで迷子になりました...

よろしくお願いします

4

1 に答える 1

4

bossylobster示唆したように、解決策は本当に簡単でした。この呼び出しを置き換えるだけです

service.freebusy().query(freebusy_query)

これで

service.freebusy().query(body=freebusy_query)

ありがとう!

于 2012-12-27T17:46:18.907 に答える