How to know if Access Token expires in Google Api PHP

一世执手 提交于 2019-12-03 20:33:19

probing this url:

https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={accessToken}

will gives you:

{
  "audience":<your_client_id>,
  "user_id":<user_id_if_userinfo.profile_was_authorized>,
  "scope":"<authorized_scope_1> <authorized_scope_1>",
  "expires_in":<time_to_live>
}

or an error:

{"error":"invalid_token"}

Catch the exceptions. Check if the HTTP error code is 401(unauthorized). This means that your access token has expired and its the time u refresh your access token.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!