我正在使用 outh2 进行身份验证。我需要它用于谷歌日历 v3 api。在本地主机上一切正常。但是当我在 heroku 服务器上发布它时,我得到了应用程序错误(基于错误代码超时 - 30 秒后)。我已经创建了单独的谷歌项目(用于谷歌 ID 和秘密)。
这是我的代码
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
FLAGS = gflags.FLAGS
def add_event(summary, location, dateTime_start, dateTime_end):
# 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='##########################',
client_secret='#######################',
scope='https://www.googleapis.com/auth/calendar',
user_agent='###########',
#access_type='offline'
)
# 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='###########################')
event = {
'summary': summary,
'location': location,
'start': {
'dateTime': dateTime_start, # '2011-06-03T10:00:00.000-07:00',
'timeZone': 'Europe/Ljubljana'
},
'end': {
'dateTime': dateTime_end, # '2011-06-03T10:25:00.000-07:00',
'timeZone': 'Europe/Ljubljana'
},
}
recurring_event = service.events().insert(calendarId='primary', body=event).execute()
return recurring_event['id']
当我从本地主机的视图中调用 add_event(summary, location, dateTime_start, dateTime_end) 时,一切正常(身份验证流程成功并且事件已添加到我的日历中)。但是在服务器上我收到超时。
更新:
我可能应该以某种方式这样做..有什么想法吗?
Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?scope=.....
If your browser is on a different machine then exit and re-run this
--noauth_local_webserver