forked from rapidwebltd/php-google-contacts-v3-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect-handler.php
31 lines (20 loc) · 967 Bytes
/
redirect-handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
// This page handles the redirect from the authorisation page. It will authenticate your app and
// retrieve the refresh token which is used for long term access to Google Contacts. You should
// add this refresh token to the 'config.json' file.
if (!isset($_GET['code'])) {
die('No code URL paramete present.');
}
$code = $_GET['code'];
require_once '../../../vendor/autoload.php';
use rapidweb\googlecontacts\helpers\GoogleHelper;
$client = GoogleHelper::getClient();
GoogleHelper::authenticate($client, $code);
$accessToken = GoogleHelper::getAccessToken($client);
if (!isset($accessToken->refresh_token)) {
echo 'Google did not respond with a refresh token. You can still use the Google Contacts API, but you may to re-authorise your application in the future. ';
echo 'Access token response:';
var_dump($accessToken);
} else {
echo 'Refresh token is: '.$accessToken->refresh_token.' - Please add this to the config file.';
}