2017-05-19 15 views
9

我獲得了來自谷歌API的Oauth此錯誤:沒有從谷歌API的Oauth的客戶端的有效原產地

idpiframe_initialization_failed「細節:」不爲客戶端的有效原點:http://127.0.0 ...... itelist這產地爲您的項目的客戶端ID

我想送從此本地路徑的請求:

http://127.0.0.1:8887/

而且我已經添加了此網址到授權的JavaScript源 部分: enter image description here

這是我的代碼:

<!-- 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> 

我該如何解決這個問題?

+0

[Google API身份驗證:客戶端的無效來源]的可能重複(http://stackoverflow.com/questions/42566296/google-api-authentication-not-valid-origin-for-the-client) – DaImTo

+1

我現在期待着同樣的問題。 – Praytic

+0

你能解決它嗎? – Praytic

回答

3

如果這一切都與您相同,請嘗試將http://localhost:8887添加到您的授權JavaScript來源中。有一點我自己有這個錯誤,並且這固定了它。知道您將不得不使用此URL來處理您的請求以及事件,但它將轉換爲http://127.0.0.1:8887/

+0

你是怎麼做到的? – BradLaney

16

我和你的問題非常相似。我試圖從localhost添加多個白名單端口,並沒有任何工作。結束刪除憑證並重新設置它們。我的設置一定是Google的一個bug結束。

+0

大聲笑這個工作...這已經是過去很多谷歌API的問題的解決方案...絕對需要記住這一個。 (wtf谷歌???) –

+0

ROFL它的工作..!這樣的愚蠢的錯誤在谷歌API – Ritesh

+0

是的,唯一的事情也適用於我。這至少是一年的問題。這是怎麼回事? –

0

我在網上的幾個地方閱讀過,人們用它來重做創建憑證以使其工作。
所以,我沒有,我創建了一個新的憑證爲同一個項目,並用我的新用戶ID和它的工作完美...貌似白名單的版本是有點flacky ...

Nb:我也用localhost而不是127.0.0.1,IPs無效。

相關問題