forked from magnetikonline/php-google-spreadsheet-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildrequesturl.php
executable file
·55 lines (40 loc) · 1.32 KB
/
buildrequesturl.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env php
<?php
require('base.php');
require('googlespreadsheet/api.php');
class BuildRequestURL extends Base {
public function execute() {
echo(
"Visit the following URL in a browser to authenticate your Google account against the OAuth2 API:\n\n" .
$this->buildURL([
GoogleSpreadsheet\API::API_BASE_URL
]) .
"After successful authentication, make note of the value of 'code=' on the URL query string for next steps.\n"
);
}
private function buildURL(array $scopeList) {
$OAuth2URLList = $this->config['OAuth2URL'];
// ensure all scopes have trailing forward slash
foreach ($scopeList as &$scopeItem) $scopeItem = rtrim($scopeItem,'/') . '/';
$buildQuerystring = function(array $list) {
$querystringList = [];
foreach ($list as $key => $value) {
$querystringList[] = rawurlencode($key) . '=' . rawurlencode($value);
}
return implode('&',$querystringList);
};
return sprintf(
"%s/%s?%s\n\n",
$OAuth2URLList['base'],$OAuth2URLList['auth'],
$buildQuerystring([
'access_type' => 'offline',
'approval_prompt' => 'force',
'client_id' => $this->config['clientID'],
'redirect_uri' => $OAuth2URLList['redirect'],
'response_type' => 'code',
'scope' => implode(' ',$scopeList)
])
);
}
}
(new BuildRequestURL(require('config.php')))->execute();