[英]Getting an access token from Google Playground to test a project
對於我使用 node js 編碼的 Google 項目應用程序,我需要擁有客戶端訪問權限才能將文件上傳到他的驅動器中。 當我測試我的代碼時,我的驅動器中沒有出現任何文件。 這可能是因為我用我的服務帳戶運行了這個東西。 所以我所做的是:因為我有一個客戶端 ID(帶有我的電子郵件等)和我用谷歌創建的密鑰,我上傳了包含這些信息的 json:
{
"web":
{
"project_id":"",
"private_key_id": "",
"private_key": "-----BEGIN PRIVATE KEY-----\n\n-----END PRIVATE KEY-----\n",
"client_email": "",
"client_id":"",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"",
"redirect_uris":["https://developers.google.com/oauthplayground"]
}
}
顯然,我的代碼中的空格不是空白。 我還在谷歌控制台中處理了客戶端 API 訪問,並使用 Drive API 應用程序添加了客戶端。 當我在終端中運行該東西時,我在終端中收到此錯誤:“錯誤:未設置密鑰或密鑰文件。” 謝謝 ! 在我的 js 中,我可以訪問 api 和包含必要信息的 keys.json 文件。
{
"installed":{
"client_id":"XXX.apps.googleusercontent.com",
"project_id":"XXX",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"XXX",
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
}
}
私鑰(和密鑰 ID)僅對服務帳戶是必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.