Gmail API access using Android

后端 未结 4 693
谎友^
谎友^ 2021-01-02 02:20

I am trying to access the Gmail API using an Android application. I have successfully requested and received an access token using all available scope combinations. But it s

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 02:39

    Although it's not described clearly, the problem is that the token obtained via GoogleAuthUtil.getToken() is cached locally and may expire. The 403 error you're receiving is due to an expired token. The correct way to handle this situation is to call GoogleAuthUtil.clearToken() to remove the locally cached token, and then call GoogleAuthUtil.getToken() to get a new one.

    Alternatively, you can keep track of the last time you requested a token, and if it's been greater than an hour (the default expiry time for these tokens) do the clearToken + getToken calls pre-preemptively.

提交回复
热议问题