1
캘린더가 있는지 확인하고 작성하지 않은 경우이 코드를 작성했습니다. 글쎄 그것은 캘린더를 만들려고 할 때 캘린더가 나타나지 않을 때 404 오류를 반환합니다. 어떤 아이디어? 나는 clientid, 비밀, 앱 키를 숨겼다.Google 캘린더 API를 사용하여 캘린더를 만들 때 오류 404가 발생했습니다.
import gflags
import httplib2
import sys, traceback
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
FLAGS = gflags.FLAGS
# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for native
# applications
# The client_id and client_secret are copied from the API Access tab on
# the Google APIs Console
FLOW = OAuth2WebServerFlow(
client_id='MY_CLIENT_ID',
client_secret='MY_SECRET',
scope='https://www.googleapis.com/auth/calendar',
user_agent='KUDOS_CALENDAR/v1')
# To disable the local server feature, uncomment the following line:
# FLAGS.auth_local_webserver = False
# If the Credentials don't exist or are invalid, run through the native client
# flow. The Storage object will ensure that if successful the good
# Credentials will get written back to a file.
storage = Storage('calendar.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = run(FLOW, storage)
# Create an httplib2.Http object to handle our HTTP requests and authorize it
# with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
# Build a service object for interacting with the API. Visit
# the Google APIs Console
# to get a developerKey for your own application.
service = build(serviceName='calendar', version='v3', http=http,
developerKey='MY_DEV_KEY')
kudos_calendar = None
try:
kudos_calendar = service.calendarList().get(calendarId='KudosCalendar').execute()
except:
print 'Calendar KudosCalendar does not exist!'
print 'Creating one right now...'
kudos_calendar_entry = {
'id': 'KudosCalendar'
}
kudos_calendar = service.calendarList().insert(body=kudos_calendar_entry).execute()
귀하의 계정에 실제 정보가 표시되는 것처럼 자세한 내용을 진단하는 것은 어렵지만 캘린더 목록을 살펴 보시기 바랍니다. 나는 당신이 처음 실행했을 때'KudosCalendar'를 만들었고 코드를 테스트 할 때마다 이미 만든 이전 캘린더 위에 새로운 캘린더를 만들려고한다는 것을 알았습니다. 새 ID를 만들려면 해당 ID가있는 이전 달력을 삭제해야합니다. – jdotjdot
안녕하세요, jdotjdot, 나는 생각했지만 캘린더 목록을보고 있으며 KudosCalendar가 없습니다 ... – siemanko