python - Google app engine Calendar API -
i instalation in site enter link description here, , works when put code example pf calendarslist fails.
the code in main.py is:
#!/usr/bin/env python # # copyright 2012 google inc. # # licensed under apache license, version 2.0 (the "license"); # may not use file except in compliance license. # may obtain copy of license @ # # http://www.apache.org/licenses/license-2.0 # # unless required applicable law or agreed in writing, software # distributed under license distributed on "as is" basis, # without warranties or conditions of kind, either express or implied. # see license specific language governing permissions , # limitations under license. # """starting template google app engine applications. use project starting point if beginning build google app engine project. remember download oauth 2.0 client secrets can obtained developer console <https://code.google.com/apis/console/> , save them 'client_secrets.json' in project directory. """ import httplib2 import logging import os import pickle apiclient.discovery import build oauth2client.appengine import oauth2decorator_from_clientsecrets oauth2client.client import accesstokenrefresherror google.appengine.api import memcache google.appengine.ext import webapp google.appengine.ext.webapp import template google.appengine.ext.webapp.util import run_wsgi_app # client_secrets, name of file containing oauth 2.0 information # application, including client_id , client_secret. # can see client id , client secret on api access tab on # google apis console <https://code.google.com/apis/console> client_secrets = os.path.join(os.path.dirname(__file__), 'client_secrets.json') # helpful message display in browser if client_secrets file # missing. missing_client_secrets_message = """ <h1>warning: please configure oauth 2.0</h1> <p> make sample run need populate client_secrets.json file found at: </p> <code>%s</code> <p>you can find client id , client secret values on api access tab in <a href="https://code.google.com/apis/console">apis console</a>. </p> """ % client_secrets http = httplib2.http(memcache) service = build("calendar", "v3", http=http) # set oauth2decorator object used authentication. add 1 or # more of following scopes in scopes parameter below. please add # scopes need. more information on using scopes please see # <https://developers.google.com/+/best-practices>. decorator = oauth2decorator_from_clientsecrets( client_secrets, scope=[ 'https://www.googleapis.com/auth/calendar.readonly', 'https://www.googleapis.com/auth/calendar', ], message=missing_client_secrets_message) class mainhandler(webapp.requesthandler): @decorator.oauth_required def get(self): test = "" page_token = none #example calendarslist while true: calendar_list = service.calendarlist().list(pagetoken=page_token).execute() if calendar_list['items']: calendar_list_entry in calendar_list['items']: test+=calendar_list_entry['summary'] page_token = calendar_list.get('nextpagetoken') if not page_token: break self.response.out.write("""<html><body> <p>congratulations, , running! @ point want add calls calendar api <code>main.py</code> file. please read <code>main.py</code> file carefully, contains detailed information in comments. more information on calendar api python library surface can visit: </p> <blockquote> <p> <a href="https://google-api-client-libraries.appspot.com/documentation/calendar/v3/python/latest/"> https://google-api-client-libraries.appspot.com/documentation/calendar/v3/python/latest/ </a> </p> </blockquote> <p> check out <a href="https://developers.google.com/api-client-library/python/start/get_started"> python client library documentation</a>, , more information on calendar api at: </p> <blockquote> <p> <a href="https://developers.google.com/google-apps/calendar/firstapp">https://developers.google.com/google-apps/calendar/firstapp</a> </p> </blockquote> """) def main(): application = webapp.wsgiapplication( [ ('/', mainhandler), (decorator.callback_path, decorator.callback_handler()), ], debug=true) run_wsgi_app(application) if __name__ == '__main__': main() and has error in line:
calendar_list = service.calendarlist().list(pagetoken=page_token).execute() httperror: <httperror 401 when requesting https://www.googleapis.com/calendar/v3/users/me/calendarlist?alt=json returned "login required"> at file client_secrets.json, when open, see client_secret , correct , client_id too, other keys don't recognize it.
can gives me help?
thanks in advance
this question has been asked few times in various ways. answer pass in argument .execute()
e.g.
....execute(http=decorator.http()) see also
why login required calendar list query not calendar queries
httperror 401 "login required" while using calendar v3 api python insert event
Comments
Post a Comment