mholt / timeliner

All your digital life on a single timeline, stored locally -- DEPRECATED, SEE TIMELINIZE (link below)

Home Page:https://timelinize.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google reauth is needed after an hour

lewurm opened this issue · comments

$ 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.

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?

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.

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.

@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?

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

@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