【发布时间】:2014-06-28 14:56:09
【问题描述】:
我正在构建一个 Google App Engine 应用并运行以下代码
<!DOCTYPE html>
<html manifest="cache.appcache">
<head>
<title>Eat Fresh</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="scripts/whitelist.js" type="text/javascript"></script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
</head>
<body>
</body>
</html>
function init() {
CLIENT_ID = "my client ID"
SCOPES = ["https://www.googleapis.com/auth/userinfo.email"]
gapi.client.load('oauth2', 'v2', signin)
}
function signin() {
gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: true}, userAuthed)
}
function userAuthed() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
checkEmail(resp)
})
}
function checkEmail(user) {
console.log(user)
var validEmail = (whiteList.indexOf(user.email) !== -1)
if (!user.code && validEmail) {
startApp()
} else {
displayError(user.email)
}
}
这是返回
Object {code: 401, message: "Invalid Credentials", data: Array[1], error: Object}
我已经用谷歌搜索和搜索,但找不到可能发生这种情况的原因。上面使用的代码直接取自我的另一个 Google App Engine 项目,它在那里完美运行。另外,如果我记得的话,我在项目中收到了类似的消息,我从中获取了此代码,并且通过更改 https://appengine.google.com/ 或 https://console.developers.google.com/project 上的设置来解决此问题。
我看了又看,找不到第一次帮助我修复它的网页。我对设置的猜测可能完全不正确,但这是我的预感。
【问题讨论】:
标签: javascript html google-app-engine web-applications oauth-2.0