排解驗證和授權問題
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明您可能會遇到的常見驗證和授權問題。
This app isn't verified
如果 OAuth 同意畫面顯示「這個應用程式未經驗證」警告,表示您的應用程式要求存取私密使用者資料的範圍。如果應用程式使用敏感範圍,就必須通過驗證程序,才能移除該警告和其他限制。在開發階段,您可以選取「進階」>「前往『{專案名稱}』(不安全)」,繼續略過這項警告。
File not found error for credentials.json
執行程式碼範例時,您可能會收到有關 credentials.json 的「找不到檔案」或「沒有這類檔案」錯誤訊息。
如果未授權桌面應用程式憑證,就會發生這個錯誤。如要瞭解如何為桌面應用程式建立憑證,請參閱「建立憑證」。
建立憑證後,請務必將下載的 JSON 檔案儲存為 credentials.json
。然後將檔案移至工作目錄。
Token has been expired or revoked
執行程式碼範例時,您可能會收到「權杖已過期」或「權杖已遭撤銷」錯誤訊息。
如果 Google 授權伺服器的存取權杖過期或遭到撤銷,就會發生這個錯誤。如要瞭解可能原因和修正方式,請參閱「更新權杖到期日」。
Python 錯誤
以下是一些常見的 Python 錯誤。
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
在 Mac OSX 中,如果 pip 安裝的 six
模組 (Python 程式庫的依附元件) 載入順序早於預設安裝的模組,就可能發生這項錯誤。如要修正這個問題,請將 pip 的安裝位置新增至 PYTHONPATH
系統環境變數:
判斷 pip 的安裝位置:
pip show six | grep "Location:" | cut -d " " -f2
請記下這個位置,下一個步驟會用到。
在 ~/.bashrc
檔案中新增下列程式碼,將 INSTALL_PATH
替換為上一步判定的位置:
export PYTHONPATH=$PYTHONPATH:INSTALL_PATH
重新載入 ~/.bashrc
檔案:
source ~/.bashrc
TypeError: sequence item 0: expected str instance, bytes found
這個錯誤是 httplib2
中的錯誤所致。如要解決這個問題,請升級至最新版 httplib2
:
pip install --upgrade httplib2
Cannot uninstall 'six'
執行 pip install
指令時,您可能會收到下列錯誤訊息:
Cannot uninstall 'six'. It is a distutils installed project and thus we
cannot accurately determine which files belong to it which would lead to
only a partial uninstall.
如果 pip 嘗試升級預先安裝的 six
套件,Mac OSX 就會發生這個錯誤。如要解決這個問題,請將 --ignore-installed six
旗標新增至 pip install
指令。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Troubleshoot authentication and authorization issues\n\nThis page describes some common issues that you might encounter involving\nauthentication and authorization.\n\n`This app isn't verified`\n-------------------------\n\nIf the OAuth consent screen displays the warning \"This app isn't verified,\" your\napp is requesting scopes that provide access to sensitive user data. If your\napplication uses sensitive scopes, your app must go through the\n[verification process](https://support.google.com/cloud/answer/7454865)\nto remove that warning and other limitations. During the development phase, you\ncan continue past this warning by selecting **Advanced \\\u003e Go to {Project Name}\n(unsafe)**.\n\n`File not found error for credentials.json`\n-------------------------------------------\n\nWhen running the code sample, you might receive a \"file not found\" or \"no such\nfile\" error message regarding credentials.json.\n\nThis error occurs when you have not authorized the desktop application\ncredentials. To learn how to create credentials\nfor a desktop application, go to\n[Create credentials](/workspace/guides/create-credentials#desktop-app).\n\nAfter you create the credentials, make sure the downloaded JSON file is saved as\n`credentials.json`. Then move the file to your working directory.\n\n`Token has been expired or revoked`\n-----------------------------------\n\nWhen running the code sample, you might receive a \"Token has been expired\" or\n\"Token has been revoked\" error message.\n\nThis error occurs when an access token from the Google Authorization Server has\neither expired or has been revoked. For information about potential causes\nand fixes, see\n[Refresh token expiration](/identity/protocols/oauth2#expiration).\n\nPython errors\n-------------\n\nThe following are some common Python errors.\n\n### `AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'`\n\nThis error can occur in Mac OSX where the default installation of the `six`\nmodule (a dependency of the Python library) is loaded before the one that pip\ninstalled. To fix the issue, add pip's install location to the `PYTHONPATH`\nsystem environment variable:\n\n1. Determine pip's install location:\n\n ```\n pip show six | grep \"Location:\" | cut -d \" \" -f2\n ```\n\n Make a note of this location because it's needed for the next step.\n2. Add the following line to your `~/.bashrc` file, replacing\n \u003cvar translate=\"no\"\u003eINSTALL_PATH\u003c/var\u003e with the location determined from the\n previous step:\n\n ```\n export PYTHONPATH=$PYTHONPATH:INSTALL_PATH\n ```\n3. Reload your `~/.bashrc` file:\n\n ```\n source ~/.bashrc\n ```\n\n### `TypeError: sequence item 0: expected str instance, bytes found`\n\nThis error is due to a bug in `httplib2`. To resolve this problem, upgrade\nto the latest version of `httplib2`: \n\n pip install --upgrade httplib2\n\n### `Cannot uninstall 'six'`\n\nWhen running the `pip install` command, you might receive the following error: \n\n```\nCannot uninstall 'six'. It is a distutils installed project and thus we\ncannot accurately determine which files belong to it which would lead to\nonly a partial uninstall.\n```\n\nThis error occurs on Mac OSX when pip attempts to upgrade the pre-installed\n`six` package. To work around this issue, add the flag\n`--ignore-installed six` to the `pip install` command."]]