在https://console.developers.google.com/apis/credentials/oauthclient中,我创建了一个“Web应用程序的客户端ID”,没有限制:清空“授权的JavaScript起源”和空的“授权重定向URI”。我收到客户端ID并将其放在页面上。
以下是最基本的页面示例。我收到的消息是:
那是一个错误。
错误:invalid_request
权限被拒绝为目标域生成登录提示。
???怎么了?
<head>
<meta name="google-signin-client_id" content="****26190863-tm7mr9racl8bgooifq2kjssb1n7teoob.apps.googleusercontent.com">
</head>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script type="text/javascript">
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
</script>
<body>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</body>
作为我的评论的后续内容,如果你查看官方文档,Authorized JavaScript origins
字段是必需的,因为Authorized redirect URI
可以留空。
文档是这样的,(Click here to check the documentation)
1.在“授权的JavaScript起源”字段中,输入应用程序的来源。您可以输入多个来源,以允许您的应用在不同的协议,域或子域上运行。你不能使用通配符。在下面的示例中,第二个URL可以是生产URL。 http://localhost:4567 https://myproductionurl.example.com
2.授权重定向URI字段不需要值。重定向URI不与JavaScript API一起使用。
希望这可以帮助!。
清空“授权的JavaScript源”并清空“授权的重定向URI”
我很确定你需要为开发(localhost)和生产提供有效信息。如果您同时使用两者,则还需要http和https版本。