0

We are trying to fetch ChromeOS end points. We use page token to fetch the next page. When the token expires, we renew the token and try to resume polling. But we get error saying page token is invalid.

If we do not use page token, we get back page 0.

So question is how do we resume polling using renewed page token?

srv, err := admin.New(client)
if err != nil {
    log.Fatalf("Unable to retrieve directory Client %v", err)
}

pageID := 1
pageToken := ""
sleep := false
for {
    log.Printf("Fetch page: %d", pageID)

    srv := srv.Chromeosdevices.List("my_customer").MaxResults(1).Projection("FULL")
    if pageToken != "" {
        srv = srv.PageToken(pageToken)
    }
    r, err := srv.Do()
    if err != nil {
        log.Fatalf("Unable to retrieve devices: %v", err)
    }

    if len(r.Chromeosdevices) == 0 {
        log.Printf("No devices found")
        break
    }

    for _, u := range r.Chromeosdevices {
        log.Printf("Page(%d) MAc: %s Model: %s", pageID, u.MacAddress, u.Model)
    }

    time.Sleep(3 * time.Second)

    pageToken = r.NextPageToken

    if pageToken == "" {
        log.Printf("Completed with all pages")
        break
    }

    pageID += 1

    if !sleep {
        log.Printf("Sleeping for 70 minutes")
        time.Sleep(4200 * time.Second)
        sleep = true
        log.Printf("Done Sleeping for 70 minutes")
    }
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 2
    "we use this code, there is a problem" ... so show the code and the specifics that result in the error? How can we determine you are not already doing what we will recommend you do, if you do not show how you use the resources? – tehhowch Aug 22 '18 at 21:37
  • After page 1 I am sleeping for 70 minutes to simulate the issue by renewing access token and using old page token – Chrome Book Aug 22 '18 at 22:06
  • This doesn't look like JavaScript / Google Apps Script code (perhaps `Go`?). please make sure you've tagged your question correctly. It looks like you could tag at least 1 client library, in addition to the language and the admin sdk... – tehhowch Aug 22 '18 at 23:07

0 Answers0