2017-06-18 864 views
1

我想使用谷歌驱动器的JavaScript API。我也设置了OAuth同意。但每次其示值误差谷歌驱动器身份验证显示错误“idpiframe_initialization_failed”

不为客户 和 有效的起源“idpiframe_initialization_failed”

实际上是什么问题?我用google搜索,谷歌搜索和谷歌搜索,但没有解决方案。我正在通过创建虚拟主机来尝试本地主机。

我现在用的样品从谷歌文档

<html> 
<head></head> 
<body> 
    <script type="text/javascript"> 
    function handleClientLoad() { 
     // Loads the client library and the auth2 library together for efficiency. 
     // Loading the auth2 library is optional here since `gapi.client.init` function will load 
     // it if not already loaded. Loading it upfront can save one network request. 
     gapi.load('client:auth2', initClient); 
    } 

    function initClient() { 
     // Initialize the client with API key and People API, and initialize OAuth with an 
     // OAuth 2.0 client ID and scopes (space delimited string) to request access. 
     gapi.client.init({ 
      apiKey: 'APIKEY', 
      discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"], 
      clientId: 'CLIENTID.apps.googleusercontent.com ', 
      scope: 'profile' 
     }).then(function() { 
      // Listen for sign-in state changes. 
      gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus); 

      // Handle the initial sign-in state. 
      updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get()); 
     }); 
    } 

    function updateSigninStatus(isSignedIn) { 
     // When signin status changes, this function is called. 
     // If the signin status is changed to signedIn, we make an API call. 
     if (isSignedIn) { 
      makeApiCall(); 
     } 
    } 

    function handleSignInClick(event) { 
     // Ideally the button should only show up after gapi.client.init finishes, so that this 
     // handler won't be called before OAuth is initialized. 
     gapi.auth2.getAuthInstance().signIn(); 
    } 

    function handleSignOutClick(event) { 
     gapi.auth2.getAuthInstance().signOut(); 
    } 

    function makeApiCall() { 
     // Make an API call to the People API, and print the user's given name. 
     gapi.client.people.people.get({ 
      'resourceName': 'people/me', 
      'requestMask.includeField': 'person.names' 
     }).then(function(response) { 
      console.log('Hello, ' + response.result.names[0].givenName); 
     }, function(reason) { 
      console.log('Error: ' + reason.result.error.message); 
     }); 
    } 
    </script> 
    <script async defer src="https://apis.google.com/js/api.js" 
    onload="this.onload=function(){};handleClientLoad()" 
    onreadystatechange="if (this.readyState === 'complete') this.onload()"> 
    </script> 
    <button id="signin-button" onclick="handleSignInClick()">Sign In</button> 
    <button id="signout-button" onclick="handleSignOutClick()">Sign Out</button> 
</body> 
</html> 

回答

0

你应该提供的HTTP调用和响应,所以我们可以检查。

但是,“不是客户的有效来源”消息表明您为您的网页提供服务的URL不是您在API控制台中配置的那些来源之一。

1

我遇到了与Google Drive JavaScript API快速入门示例相同的问题。 我从开始的时候就清除了谷歌浏览器的缓存,之后它工作... 希望它有帮助! :)