-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauth.php
More file actions
32 lines (25 loc) · 809 Bytes
/
Copy pathauth.php
File metadata and controls
32 lines (25 loc) · 809 Bytes
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
32
<?php
function auth()
{
// required
include 'apiclient/vendor/autoload.php';
$credentials = 'oauth-credentials.json';
$token_path = 'refresh-token.json';
// get token
if (file_exists($token_path)) {
$refresh_token = json_decode(file_get_contents($token_path), true);
} else {
die ('refresh token not found');
}
// make new object
$client = new Google\Client();
// set credentials
$client->setAuthConfig($credentials);
// make client can access data from your google
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
// set refresh token
$client->refreshToken($refresh_token);
return $client;
}
?>