You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用Google API认证时出现404错误,求问题排查解决方法

Google API 404 Error Troubleshooting (People API + Authentication)

Let’s break down the possible issues causing that 404 error with your Google API setup—here are the key checks and fixes to try:

1. Invalid Discovery Document URL

Your discoveryDocs points to an incorrect endpoint: https://people.googleapis.com/$discovery/rest?version=v1—this URL will return a 404 because $discovery is not part of Google’s actual discovery API structure. Replace it with the valid People API v1 discovery document:

var discoveryDocs = ["https://www.googleapis.com/discovery/v1/apis/people/v1/rest"];

2. Wrong Script Source for Google’s API Client

In your HTML, you’re loading a local js/api.js file instead of Google’s official API client library. This means your code can’t connect to Google’s API services properly. Update the script tag to:

<script async defer src="https://apis.google.com/js/api.js" onload="this.onload=function(){};handleClientLoad()" onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>

3. Scope Mismatch for People API Access

You’re using the cloud-platform scope (https://www.googleapis.com/auth/cloud-platform), which is not intended for accessing the People API. Since your code fetches user profile and email data, switch to a People API-specific scope like:

var scopes = 'https://www.googleapis.com/auth/people.readonly';

Unrelated scopes can cause authorization issues that manifest as unexpected 404s or permission errors.

4. Double-Check Google Console Configuration

Even though you mentioned setting up credentials and enabling the API, verify these details again:

  • Confirm the People API is explicitly enabled in your Google Cloud Console project (not just a different API).
  • For your API Key, ensure the People API is allowed under the key’s restrictions (if you set API-specific limits).
  • For your Client ID, make sure the JavaScript origin exactly matches your app’s running domain/port (e.g., http://localhost:3000 for local development—include protocol and port).

After applying these fixes, test your auth flow again—the 404 error should resolve, and you should be able to pull user data via the People API.

内容的提问来源于stack exchange,提问作者Yvonne Aburrow

火山引擎 最新活动