Fil*_*ano 29 javascript oauth-2.0 google-oauth
我从Google API Oauth收到此错误:
idpiframe_initialization_failed",详细信息:"不是客户端的有效来源:http://127.0.0....为项目的客户端ID列出此来源
我正在尝试从此本地路径发送请求:
我已将此URL添加到Authorized JavaScript origin部分:
这是我的代码:
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
</script>
<!-- END Pre-requisites -->
<!-- Continuing the <head> section -->
<script>
function start() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'MY CLIENT ID.apps.googleusercontent.com',
// Scopes to request in addition to 'profile' and 'email'
//scope: 'https://www.google.com/m8/feeds/'
});
});
}
</script>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
<script>
$('#signinButton').click(function() {
// signInCallback defined in step 6.
auth2.grantOfflineAccess().then(signInCallback);
});
</script>
<!-- Last part of BODY element in file index.html -->
<script>
function signInCallback(authResult) {
if (authResult['code']) {
// Hide the sign-in button now that the user is authorized, for example:
$('#signinButton').attr('style', 'display: none');
// Send the code to the server
$.ajax({
type: 'POST',
url: 'http://example.com/storeauthcode',
// Always include an `X-Requested-With` header in every AJAX request,
// to protect against CSRF attacks.
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
// Handle or verify the server response.
},
processData: false,
data: authResult['code']
});
} else {
// There was an error.
}
}
</script>
<!-- ... -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
And*_*ash 73
我和你的问题非常相似.我尝试添加多个白名单端口localhost
,但没有任何工作.结束删除凭据并重新设置.对于我的设置,谷歌一定是个bug.
Kir*_*kiy 29
重置Chrome缓存可以为我解决。长按“重新加载”按钮,然后长按“清空缓存和硬重新加载”。
如果对您来说完全相同,请尝试将http:// localhost:8887添加到您的授权JavaScript源代码中.在某些时候我自己有这个错误,这就解决了.知道您必须将此URL用于您的请求以及事件,尽管它转换为http://127.0.0.1:8887/.
小智 6
我也有同样的问题;但这对我有用:
我在网络上的许多地方阅读过,人们经常使用这些地方来重做凭据的创建,以使其生效。
所以我做到了,我为同一项目创建了一个新凭据,并使用了新的用户ID,它运行得非常完美。
Nb:我也使用localhost而不是127.0.0.1,IP无效。
我摆弄了大约 10 分钟,然后当我在浏览器中尝试http://localhost/(而不是 127.0.0.1)时它终于起作用了
在每个你可以做白名单的地方添加了网址:https : //console.developers.google.com/apis/credentials/
归档时间: |
|
查看次数: |
28797 次 |
最近记录: |