Google api refresh_token null and how to refresh access token(Google api refresh_token null 以及如何刷新访问令牌)
问题描述
I use HWIO Bundle for google api and when I have response from google refreshToken = null why? How to refresh token
because in google/apiclient, "version": "1.1.7" in function need refresh_token
this my access token
{"access_token":"ya29.Ci8lA1JTu9CB81dOFy-nzszViRgCI2CvvKVrCd0Lq-8I0QR_dIrl-_7RccdGt1Islg","token_type":"Bearer","expires_in":3578,"id_token":"xxxx","created":1468957368}
not have refresh token because from google get refreshToken = null or need set null with key refresh token or this dosn't metter ?
still have exception - The OAuth 2.0 access token has expired, and a refresh token is not available. Refresh tokens are not returned for responses that were auto-approved.
how to refresh token and how to with token get refresh token, for refresh token ?
I try
- In my code too
$client = new Google_Client()
but in wrapper, in constructor. I get access token from HWIO bundle:
and after I get access token I set it in DB. Then in Action I create wrapper for google api (new Google Client ()) and set this client my accesss token from DB. How to refresh my access token? I try in action use function google api lib setAccessType and setApprovalPrompt, but not efect
config this is:
and if in action I set to Google Client some parameters this is same if I add constructorI, so what I'am doing wrong ?
The refresh_token is only returned on the first request. When you refresh the access token a second time it returns everything except the refresh_token and the file_put_contents removes the refresh_token when this happens the second time.
Modifying the code as following will merge in the original access token with the new one (see: array_merge). This way you will be able to preserve your refresh_token for future requests. I have submitted the following fix to Google, hope they update it at some point.
See docs for more info
这篇关于Google api refresh_token null 以及如何刷新访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!