🚸 Persist refreshed token

This commit is contained in:
chaoqun authored and OpenWaygate committed 2024-04-21 15:54:43 +08:00
1 parent 4eb34bb36d
commit ce5f0b223e
2 files changed
+7 -5

No files matched your search

+3 -3
View File
@@ -64,7 +64,7 @@ Here are the features that are currently supported by yutu, and the ones that ar
- [x] update, 50
- [ ] delete, 50
- activities
- [ ] list, 1
- [x] list, 1
- captions
- [ ] list, 50
- [ ] insert, 400
@@ -87,8 +87,8 @@ Here are the features that are currently supported by yutu, and the ones that ar
- [ ] list, 1
- [ ] insert, 50
- [ ] update, 50
- guideCategories
- [ ] list, 1
- <s>guideCategories</s>
- [x] <s>list, 1 deprecated API</s>
- i18nLanguages
- [ ] list, 1
- i18nRegions
+4 -2
View File
@@ -21,7 +21,7 @@ import (
var (
credential string = "client_secret.json"
cacheFile string = "youtube.cache.json"
cacheFile string = "youtube.token.json"
errGetUser error = errors.New("unable to get current user")
errCreateSvc error = errors.New("unable to create YouTube service")
errReadPrompt error = errors.New("unable to read prompt")
@@ -68,6 +68,9 @@ func getClient(ctx context.Context, scope ...string) *http.Client {
} else if !token.Valid() {
tokenSource := config.TokenSource(ctx, token)
token, err = tokenSource.Token()
if token != nil {
saveToken(cacheFile, token)
}
if err != nil {
return newClient(ctx, config, cacheFile)
}
@@ -208,7 +211,6 @@ func tokenFromFile(file string) (*oauth2.Token, error) {
}
func saveToken(file string, token *oauth2.Token) {
fmt.Printf("Saving credential file to %s\n", file)
f, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
log.Fatalln(errors.Join(errCacheToken, err))