2013-05-14 7 views
1

Я делаю установку на сайте enter link description here и работает хорошо, но когда я помещаю код из примера pf calendarsList, он терпит неудачу.Google app engine Calendar API

Код в main.py является:

#!/usr/bin/env python 
# 
# Copyright 2012 Google Inc. 
# 
# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 
# 
#  http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 
# 

"""Starting template for Google App Engine applications. 

Use this project as a starting point if you are just beginning to build a Google 
App Engine project. Remember to download the OAuth 2.0 client secrets which can 
be obtained from the Developer Console <https://code.google.com/apis/console/> 
and save them as 'client_secrets.json' in the project directory. 
""" 

import httplib2 
import logging 
import os 
import pickle 

from apiclient.discovery import build 
from oauth2client.appengine import oauth2decorator_from_clientsecrets 
from oauth2client.client import AccessTokenRefreshError 
from google.appengine.api import memcache 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp import template 
from google.appengine.ext.webapp.util import run_wsgi_app 


# CLIENT_SECRETS, name of a file containing the OAuth 2.0 information for this 
# application, including client_id and client_secret. 
# You can see the Client ID and Client secret on the API Access tab on the 
# Google APIs Console <https://code.google.com/apis/console> 
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json') 

# Helpful message to display in the browser if the CLIENT_SECRETS file 
# is missing. 
MISSING_CLIENT_SECRETS_MESSAGE = """ 
<h1>Warning: Please configure OAuth 2.0</h1> 
<p> 
To make this sample run you will need to populate the client_secrets.json file 
found at: 
</p> 
<code>%s</code> 
<p>You can find the Client ID and Client secret values 
on the API Access tab in the <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 up an OAuth2Decorator object to be used for authentication. Add one or 
# more of the following scopes in the scopes parameter below. PLEASE ONLY ADD 
# THE SCOPES YOU NEED. For 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 from calendarsList 
     while True: 
      calendar_list = service.calendarList().list(pageToken=page_token).execute() 
      if calendar_list['items']: 
       for 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, you are up and running! At this point you will want to add 
    calls into the Calendar API to the <code>main.py</code> file. Please read the 
    <code>main.py</code> file carefully, it contains detailed information in 
    the comments. For more information on the Calendar API Python library 
    surface you 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> 
    Also check out the <a 
    href="https://developers.google.com/api-client-library/python/start/get_started"> 
    Python Client Library documentation</a>, and get more information on the 
    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() 

и есть ошибка в строке:

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"> 

в файле client_secrets.json, когда я открываю, я вижу свою client_secret и это правильно, и мой client_id тоже, другие ключи я его не узнаю.

Может ли кто-нибудь мне помочь?

Заранее благодарен

ответ

0

Я ударился головой об этом в течение длительного времени с недействительным полномочием является сообщением об ошибке.

Запуск в среде разработки, который вы должны дать авторизацию, эта ссылка очень помогла мне!

https://gist.github.com/pwalsh/b8563e1a1de3347a8066