问题描述
我试图弄清楚Google日历,但是当我需要推送或获取数据时,我无法理解哪些字符串需要存储在我的数据库中以获取访问令牌。
我向Google发出请求并返回:
?代码= 4 / xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#
然后我验证:
$ client-> authenticate($ _ GET ['code']);
然后我得到访问令牌:
$ client-> getAccessToken()
本届会议。但是,我不希望每次都要求用户进行身份验证。我可以存储$ _GET ['code']字符串,然后请求一个访问令牌,而不必让用户每次都进行验证?
谢谢。
是的,这是完全可能的。
您将要阅读。这会阻止用户从您的应用程序获得每次授权的同意屏幕。
要使用离线访问,您需要应用以下代码代码片段:
$ client-> setAccessType(offline);
您也可以在此链接阅读有关OAuth 2.0的更多信息:
希望它有帮助,祝你好运!
Im trying to figure out Google calendars but I cant make sense out of which string I need to store in my db to fetch access tokens when I need to push or get data.
I make my request to Google and they return:
?code=4/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#
Then I authenticate:
$client->authenticate($_GET['code']);
Then I get access token:
$client->getAccessToken()
Everything works great for this session. But, I dont want to have to ask the user to authenticate each time. Can I store the $_GET['code'] string and then request an access token without having the user to authenticate each time?
Thanks.
Yes, this is absolutely possible.
You will want to read about offline access from the OAuth 2.0 for Web Server Applicaitons. This will prevents user from your application to be prompted with the consent screen for authorization every time.
To use the 'offline access', you will need to apply the following code snippet to your app:
$client->setAccessType("offline");
You may also want to read more about the OAuth 2.0 at this link: https://developers.google.com/identity/protocols/OAuth2
Hope it helps and Good luck!
这篇关于Google日历API存储代码或访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!