-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetRefreshToken.php
More file actions
executable file
·32 lines (28 loc) · 1.21 KB
/
Copy pathgetRefreshToken.php
File metadata and controls
executable file
·32 lines (28 loc) · 1.21 KB
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
#!/usr/bin/env php
<?php
# generate auth config file using oauth credential webservice in Google API console
# download auth config and remove client surrounding object because Google sucks
# Execute from console using "php getRefreshToken.php"
require('config.php');
$client = new Google_Client();
$client->setApplicationName('YTQR');
$client->setScopes([
'https://www.googleapis.com/auth/youtube.readonly',
]);
$client->setAuthConfig( YTQR_AUTH_CONFIG_FILE );
$client->setAccessType('offline');
// $client->setRedirectUri('https://example.org/123'); // comes from YTQR_AUTH_CONFIG_FILE
// Request authorization from the user.
$client->setPrompt('consent'); // required for refreshToken
$client->setApprovalPrompt("consent");
$client->setIncludeGrantedScopes(true); // incremental auth
$authUrl = $client->createAuthUrl();
printf("Open this link in your browser:\n%s\n", $authUrl);
print('Enter verification code: ');
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
$client->setAccessToken($accessToken);
$refreshToken = $client->getRefreshToken();
print('Write token to '. YTQR_REFRESH_TOKEN_FILE .': '. $refreshToken . "\n");
?>