Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google reauth is needed after an hour #77

Open
lewurm opened this issue Jan 5, 2022 · 6 comments
Open

Google reauth is needed after an hour #77

lewurm opened this issue Jan 5, 2022 · 6 comments

Comments

@lewurm
Copy link

lewurm commented Jan 5, 2022

$ timeliner -config ../timeliner.toml reauth google_photos/me@gmail.com; uptime; timeliner -config ../timeliner.toml get-latest google_photos/me@gmail.com; uptime
23:13  up 1 day,  6:53, 7 users, load averages: 1.31 1.91 2.14
2022/01/05 00:13:13 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 1/10)
2022/01/05 00:13:23 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 2/10)
2022/01/05 00:13:33 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 3/10)
2022/01/05 00:13:43 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 4/10)
2022/01/05 00:13:53 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 5/10)
2022/01/05 00:14:03 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 6/10)
2022/01/05 00:14:13 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 7/10)
2022/01/05 00:14:23 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 8/10)
2022/01/05 00:14:33 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 9/10)
2022/01/05 00:14:43 [ERROR] google_photos/me@gmail.com: doing API request: >>> Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set <<< - retr
ying... (attempt 10/10)
2022/01/05 00:14:53 [ERROR] google_photos/me@gmail.com: a listing goroutine errored: getting items on next page: requesting next page: Post "https://photoslibrary.googleapis.com/v1/mediaItems:search": oauth
2: token expired and refresh token is not set
2022/01/05 00:14:53 [ERROR][google_photos/me@gmail.com] Getting latest: getting items from service: one or more errors: getting items on next page: requesting next page: Post "https://photoslibrary.googleap
is.com/v1/mediaItems:search": oauth2: token expired and refresh token is not set
 0:14  up 1 day,  7:55, 7 users, load averages: 0.68 1.14 1.23

I tried to add some reauth hack when this failure happens, but that didn't work:

diff --git a/datasources/googlephotos/googlephotos.go b/datasources/googlephotos/googlephotos.go
index c14494a..3e5f71c 100644
--- a/datasources/googlephotos/googlephotos.go
+++ b/datasources/googlephotos/googlephotos.go
@@ -314,6 +314,21 @@ func (c *Client) apiRequestWithRetry(method, endpoint string, reqBodyData, respI
                if err != nil {
                        log.Printf("[ERROR] %s/%s: doing API request: >>> %v <<< - retrying... (attempt %d/%d)",
                                DataSourceID, c.userID, err, i+1, maxTries)
+                       if strings.Contains(err.Error(), "token expired and refresh token is not set") {
+                               log.Printf("HACK: reauth that puppy")
+                               // open the timeline
+                               tl, err := timeliner.Open("./timeliner_repo")
+                               if err != nil {
+                                       log.Fatalf("[FATAL] Opening timeline: %v", err)
+                               }
+                               defer tl.Close()
+                               // reauth
+                               err2 := tl.Authenticate(DataSourceID, c.userID)
+                               if err2 != nil {
+                                       log.Fatalf("[FATAL] Authenticating: %v", err2)
+                               }
+
+                       }
                        time.Sleep(10 * time.Second)
                        continue
                }

Probably another timerliner.Open isn't right here, but I didn't figure out how to pass down the handle from main.go due to my lack of Go knowledge 🙂

Any insight would be appreciated, also if it happens for other people.

@mholt
Copy link
Owner

mholt commented Jan 5, 2022

Huh, that's weird. A refresh token should be set. Might be similar to #20. I've never been able to reproduce the issue... would you be able to dig in a little more and figure out why a refresh token isn't set?

@khaneliman
Copy link

I have this issue, as well. It made syncing too much hassle restarting every hour with a large photo library so i stopped trying for a bit.

@mholt
Copy link
Owner

mholt commented Jan 8, 2022

What would be helpful is putting in some debug lines that could print out some state and help us know why a refresh token isn't set. If one of you who can reproduce the issue could do that, it would help us solve the problem.

@lewurm
Copy link
Author

lewurm commented Jan 8, 2022

@mholt I can reproduce it reasonable well, but I'm not sure what kind of debug output would help. Would you mind posting a patch here with the debug lines that you think would be helpful?

@mholt
Copy link
Owner

mholt commented Jan 8, 2022

Sure, thanks. I just need a chance to sit down at my computer first. In the meantime I'd look at oauth-related files.

@mholt
Copy link
Owner

mholt commented Jan 24, 2022

@lewurm Sorry I never got around to this, I'm still really busy in both my work and personal life right now. But you could start by putting fmt.Println() lines all over this file: https://github.com/mholt/timeliner/blob/cf155164e218ca1ad6ad600152cd2436c88dba43/oauth2client/localapp.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants