2017-04-17 9 views
0

GoogleログインAPIをテストしようとしています。クライアントログの後にいくつかの基本データを取得したい。プロファイルキーを取得しようとすると、APIキーが無効なエラーとなる

私はここ(https://developers.google.com/identity/sign-in/web/devconsole-project

GoogleのAPIコンソールプロジェクトとクライアントIDを作成した公式のコード(https://developers.google.com/api-client-library/javascript/samples/samples#LoadinganAPIandMakingaRequest)をグーグルで:

<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: '5v2RzP7-xyQGNjxrD5suoPL9', 
      discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"], 
      clientId: '298062822261-e5c09q8191mkho0o7n3n3obiq2eq2p3f.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' 
     }).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> 

ClientIdをしてAPIキーは私のG​​oogleのAPIからです。

私は400

{ 
    "error": { 
    "code": 400, 
    "message": "API key not valid. Please pass a valid API key.", 
    "status": "INVALID_ARGUMENT", 
    "details": [ 
     { 
     "@type": "type.googleapis.com/google.rpc.Help", 
     "links": [ 
      { 
      "description": "Google developers console", 
      "url": "https://console.developers.google.com" 
      } 
     ] 
     } 
    ] 
    } 
} 

エラーを受け取り、私は私のAPIキーを聖霊降臨祭の何が悪いのを理解していません。私はGoogleのドキュメントからすべての手順に従った。

答えて

0

APIキーとしてクライアントシークレットを使用しているようです。ではない?

APIキーを取得するには、それを作成する必要があります。資格証明書(DEVコンソール)の下で

資格を作成する上でクリックして、私は新しいAPIキーを聖霊降臨祭の修正APIキー

+0

をしかし、私は同じエラーを持っています。 –

+0

まったく同じエラーですか? – Seak

+0

エラー400 ..しかし、なぜ私はエラーの内容を開くことができないのかわかりません。 –

関連する問題