2013-05-14 5 views
1

enter link description here 사이트에서 설치 작업을 수행하며 잘 작동하지만 예제 pf calendarsList의 코드를 입력하면 실패합니다.Google 앱 엔진 캘린더 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() 

와 라인에 오류가 있습니다 내가 열 때, 나는 나의 client_secret를 참조 파일 client_secrets.json에서

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_id, 나는 그것을 인식하지 못하는 다른 열쇠입니다.

누구든지 내게 도움을 줄 수 있습니까?

미리 감사드립니다.

답변