Google+ API: How can I use RefreshTokens to avoid requesting access every time my app launches?

前端 未结 5 1437
不知归路
不知归路 2020-12-02 08:45

I\'m trying to use the Google+ API to access info for the authenticated user. I\'ve copied some code from one of the samples, which works fine (below), however I\'m having t

5条回答
  •  伪装坚强ぢ
    2020-12-02 09:44

    The general idea is as follows:

    1. You redirect the user to Google's Authorization Endpoint.

    2. You obtain a short-lived Authorization Code.

    3. You immediately exchange the Authorization Code for a long-lived Access Token using Google's Token Endpoint. The Access Token comes with an expiry date and a Refresh Token.

    4. You make requests to Google's API using the Access Token.

    You can reuse the Access Token for as many requests as you like until it expires. Then you can use the Refresh Token to request a new Access Token (which comes with a new expiry date and a new Refresh Token).

    See also:

    • The OAuth 2.0 Authorization Protocol
    • Google's OAuth 2.0 documentation

提交回复
热议问题