用戶端密鑰
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
.NET 的 Google API 用戶端程式庫
client_secrets.json
用於儲存
client_id
、client_secret
和其他 OAuth 2.0 參數。
client_secrets.json
檔案是 JSON 格式的檔案
,其中包含用戶端 ID、用戶端密鑰和其他 OAuth 2.0 參數。
以下是網頁應用程式的 client_secrets.json
範例檔案:
{
"web": {
"client_id": "asdfjasdljfasdkjf",
"client_secret": "1912308409123890",
"redirect_uris": ["https://www.example.com/oauth2callback"],
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"
}
}
以下是已安裝應用程式的 client_secrets.json
範例檔案:
{
"installed": {
"client_id": "837647042410-75ifg...usercontent.com",
"client_secret":"asdlkfjaskd",
"redirect_uris": ["http://localhost"],
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"
}
}
這種格式定義了以下兩種用戶端 ID 類型的其中之一:
web
:網頁應用程式。
installed
:已安裝的應用程式。
web
和 installed
子物件有
下列必要成員:
-
client_id
(字串):用戶端 ID。
-
client_secret
(字串):用戶端密鑰。
這個檔案的所有其他成員皆為選用,
.NET 用戶端程式庫則不會用到。
動機
傳統上,OAuth 2.0 端點的供應商是
使用其服務複製及貼上用戶端 ID 的使用者
轉換為有效程式碼
這個方法容易出錯,並提供不完整的圖片
確保 OAuth 2.0 運作所需的資訊。
(OAuth 2.0 也需要知道所有端點,
並設定重新導向 URI)。
如果服務供應商提供可下載的 client_secrets.json
檔案和用戶端程式庫
那麼導入 OAuth 2.0 不僅更簡單,也較不容易出錯。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThe Google APIs client library for .NET utilizes \u003ccode\u003eclient_secrets.json\u003c/code\u003e files to store OAuth 2.0 credentials like \u003ccode\u003eclient_id\u003c/code\u003e, \u003ccode\u003eclient_secret\u003c/code\u003e, and other parameters.\u003c/p\u003e\n"],["\u003cp\u003eThese JSON files define client ID types as either \u003ccode\u003eweb\u003c/code\u003e for web applications or \u003ccode\u003einstalled\u003c/code\u003e for installed applications, each requiring \u003ccode\u003eclient_id\u003c/code\u003e and \u003ccode\u003eclient_secret\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003eclient_secrets.json\u003c/code\u003e files simplifies OAuth 2.0 implementation by providing a centralized, downloadable configuration instead of manual entry, reducing errors.\u003c/p\u003e\n"]]],[],null,[]]