Google api 在Google API v3 for python中使用两条腿

Google api 在Google API v3 for python中使用两条腿,google-api,google-calendar-api,google-oauth,Google Api,Google Calendar Api,Google Oauth,我有这里描述的代码。 我需要在日历中创建很多活动 我找不到办法让它工作。使用双腿似乎不太受欢迎 导入系统 导入httplib2 从rfc3339导入rfc3339 从apiclient.discovery导入生成 从oauth2client.file导入存储 从oauth2client.client导入AccessTokenRefreshError 从oauth2client.client导入流\u从\u clientsecrets 从oauth2client.tools导入运行 进口皮茨 导入

我有这里描述的代码。 我需要在日历中创建很多活动

我找不到办法让它工作。使用双腿似乎不太受欢迎

导入系统 导入httplib2 从rfc3339导入rfc3339 从apiclient.discovery导入生成 从oauth2client.file导入存储 从oauth2client.client导入AccessTokenRefreshError 从oauth2client.client导入流\u从\u clientsecrets 从oauth2client.tools导入运行 进口皮茨 导入日期时间 导入时间 起始时区=pytz.时区(“欧洲/伦敦”) end_zone=pytz.时区(“欧洲/奥斯陆”) 开始时间=日期时间。日期时间(2013,8,13,15,0,tzinfo=开始时间区域) end_time=datetime.datetime(2013,8,16,19,0,tzinfo=end_区域) flow=flow\u from\u clientsecrets('client\u secrets.json', 范围=https://www.googleapis.com/auth/calendar', 重定向http://localhost') 存储=存储('credentials.dat') 凭据=存储。获取() 如果凭据为无或凭据无效: 凭据=运行(流、存储) http=httplib2.http() http=凭据。授权(http) service=build('calendar','v3',http=http) 尝试: 事件={ “开始”:{ “日期时间”:开始时间 }, “结束”:{ “日期时间”:结束时间 }, “总结”:“新事件”, “地点”:“法国巴黎” } service.events().insert(calendarId='primary',body=event).execute() 打印“结束” 除AccessTokenRefreshError外: 打印('凭据已被吊销') 我以这种方式更新了代码(因为我没有重定向)

#/usr/bin/python
导入系统
导入httplib2
从rfc3339导入rfc3339
从apiclient.discovery导入生成
从oauth2client.file导入存储
从oauth2client.client导入AccessTokenRefreshError
从oauth2client.client导入流\u从\u clientsecrets
从oauth2client.tools导入运行
进口皮茨
导入日期时间
导入时间
起始时区=pytz.时区(“欧洲/伦敦”)
end_zone=pytz.时区(“欧洲/奥斯陆”)
开始时间=日期时间。日期时间(2013,8,13,15,0,tzinfo=开始时间区域)
end_time=datetime.datetime(2013,8,16,19,0,tzinfo=end_区域)
flow=flow\u from\u clientsecrets('client\u secrets.json',
范围=https://www.googleapis.com/auth/calendar',
重定向(urn:ietf:wg:oauth:2.0:oob)
auth\u uri=flow.step1\u get\u authorize\u url()
打印('访问此站点!')
打印(auth_uri)
代码=原始输入('插入给定代码!')
凭证=流程。步骤2_交换(代码)
打印(凭证)
打开('credentials.dat','wr')作为f:
f、 写入(credentials.to_json())
存储=存储('credentials.dat')
凭据=存储。获取()
如果凭据为无或凭据无效:
凭据=运行(流、存储)
http=httplib2.http()
http=凭据。授权(http)
service=build('calendar','v3',http=http)
尝试:
事件={
“开始”:{
“日期时间”:开始时间
},
“结束”:{
“日期时间”:结束时间
},
“总结”:“新事件”,
“地点”:“法国巴黎”
}
service.events().insert(calendarId='primary',body=event).execute()
打印“结束”
除AccessTokenRefreshError外:
打印('凭据已被吊销')
因此,当我运行脚本时,它会打开一个窗口广告,要求我登录。因此,我输入了我的gmail用户名/密码,之后出现以下错误:

Error: redirect_uri_mismatch
The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob did not match a registered redirect URI 

错误消息表明您使用的client_secrets.json不适用于已安装的应用程序。尝试在API控制台中重新创建客户端ID,并确保指定它是已安装的应用程序。

代码的身份验证部分似乎正确。你在执行死刑时犯了什么错误?@jay lee,你好,jay,我已经更新了我的问题。希望它有意义