我將Google雲端硬盤集成到我的應用中。並且每次在連接的雲端硬盤帳戶中更改內容時,都希望收到推送通知/網絡掛鉤。自驅動器帳戶連接一小時後,access_token失效,之後我無法接收任何webhook。 如何自動刷新並自動刷新?刷新Google驅動器access__token
0
A
回答
1
您可以使用刷新令牌。訪問令牌可以由刷新令牌更新。這個刷新標記可以被檢索如下。首先,以下信息是檢索refreshtoken所必需的。
- 客戶端ID
- 客戶端密鑰
- 重定向URI
- 作用域
從你的問題,看來你已經有一個的accessToken。所以我認爲你有以上信息。
接下來,使用上述信息,它將檢索您的應用程序可用來獲取訪問令牌的授權碼。請按如下方式製作URL並將其放到瀏覽器中,然後單擊進行授權。我總是使用此URL檢索代碼並檢索刷新標記。刷新令牌可以通過包含access_type = offline來檢索。
https://accounts.google.com/o/oauth2/auth?
response_type=code&
approval_prompt=force&
access_type=offline&
client_id=### your_client_ID ###&
redirect_uri=### edirect_uri ###&
scope=### scopes ###
授權代碼顯示在瀏覽器上或作爲URL。您可以使用代碼檢索刷新令牌。
以下2個樣本是python腳本。
獲取刷新令牌:
import requests
r = requests.post(
'https://accounts.google.com/o/oauth2/token',
headers={'content-type': 'application/x-www-form-urlencoded'},
data={
'grant_type': 'authorization_code',
'client_id': '#####',
'client_secret': '#####',
'redirect_uri': '#####',
'code': '#####',
}
)
檢索訪問令牌使用刷新令牌:
import requests
r = requests.post(
'https://www.googleapis.com/oauth2/v4/token',
headers={'content-type': 'application/x-www-form-urlencoded'},
data={
'grant_type': 'refresh_token',
'client_id': '#####',
'client_secret': '#####',
'refresh_token': '#####',
}
)
你可以在這裏看到詳細信息來源。 https://developers.google.com/identity/protocols/OAuth2WebServer
相關問題
- 1. Google驅動器transferOwnership
- 2. 將Google驅動器嵌入Google頁面
- 3. Selenium驅動 - 等待頁面刷新
- 4. selenium web驅動等到頁面刷新
- 5. 使用驅動器API訪問Google驅動器電子表格
- 6. 帶Google驅動器的動態Nivo Slider
- 7. Google Apps域名:驅動器遷移器
- 8. 如何在Python中刷新網絡驅動器映射
- 9. 刷新Google地圖
- 10. AppleScript檢測新驅動器
- 11. Android:自動刷新Google地圖
- 12. 手動刷新令牌 - Google API
- 13. ImportJSON自動刷新Google表格
- 14. 自動刷新Google地圖標記
- 15. 如何在使用Google Cloud SQL JDBC驅動程序時刷新OAuth令牌?
- 16. 如何在驅動器上創建新的Google表單?
- 17. Net :: Google :: AuthSub登錄失敗,新的谷歌驅動器版本
- 18. Google驅動器分段上傳
- 19. Google驅動器虛擬主機
- 20. Google驅動器和機密文件
- 21. Google驅動器getMimeType只返回空值
- 22. 使用VBA上傳到Google驅動器?
- 23. Google驅動器 - 如何使用php
- 24. 將文件提交給Google驅動器
- 25. Google驅動器oauth令牌錯誤
- 26. file.getParents返回null(Google驅動器)
- 27. Google驅動器文件預覽api
- 28. Google驅動器API和服務帳戶
- 29. Google驅動器v2 api示例
- 30. Google Apps腳本 - 在驅動器