Google App Engine到日历身份验证

时间:2013-06-05 16:49:42

标签: google-app-engine oauth-2.0 google-calendar-api

我是App Engine的新用户,我正在尝试编写一个应用程序,该应用程序将访问Google日历以获取当前时间内任何事件的详细信息。我很难看到身份验证应如何工作以允许访问日历。我相信OAuth2是首选的身份验证选项,所以我有一个client_secrets.json文件,其中包含我单独创建的API Access项目中的ClientID和Client Secret:

{
"web":{
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"client_secret":"xxxxxxx",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"client_email":"xxxxxxx@developer.gserviceaccount.com",
"redirect_uris":["https://myapp.appspot.com/oauth2callback"],
"client_x509_cert_url":"https://www.googleapis.com/robot/v1/metadata/x509/xxxxxxx@developer.gserviceaccount.com",
"client_id":"123456789.apps.googleusercontent.com",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"javascript_origins":["https://myapp.appspot.com"]
}
}

这是使用“下载JSON”选项直接从API Access项目导出。当我部署我的应用引擎应用程序时,出现错误:

Error: redirect_uri_mismatch
The redirect URI in the request: http://myapp.appspot.com/oauth2callback did not match a registered redirect URI
Learn more
Request Details
scope=https://www.googleapis.com/auth/calendar
response_type=code
access_type=offline
redirect_uri=https://myapp.appspot.com/oauth2callback
display=page
client_id=123456789.apps.googleusercontent.com

这一切对我来说都很好,所以我不确定错误告诉我的是什么。我是否需要以某种方式将App Engine应用程序链接到API Access项目。我错过了其他一些基本的东西。

如果有任何其他信息可以帮助您了解设置,请告诉我们。我希望保持这个职位小。

1 个答案:

答案 0 :(得分:1)

有评论here说:

  

当您创建凭据时,您可能表示了   您创建的客户端凭据是针对Web应用程序的   而不是安装的应用程序。当你这样做时,你输入一个   重定向该组凭据的URI。您正在使用的样本是   使用带外重定向URI来安装应用程序   与您指定的不匹配,因此不允许您这样做   竞争认证流程。这是为了保护您免受恶意攻击   使用您的客户端凭据。打开API控制台并创建一个新的   “已安装的应用程序”的客户端ID,而不是“Web应用程序”   这应该有用。

您是否设置了Web应用程序或已安装的应用程序?