This question already has an answer here:
I am trying to implement the PlaylistItems: insert
YouTube Data API sample, and when I try to run it, I get the following:
Notice: Use of undefined constant STDIN - assumed 'STDIN' in /example/path/to/script.php on line 51
The function containing this line does not make it clear where STDIN gets it's value:
function getClient() {
$client = new Google_Client();
$client->setApplicationName('API Samples');
$client->setScopes('https://www.googleapis.com/auth/youtube.force-ssl');
// Set to name/location of your client_secrets.json file.
$client->setAuthConfig('client_secrets.json');
$client->setAccessType('offline');
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:
%s
", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN)); // <--- Appears to be the problem
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if(!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s
", $credentialsPath);
}
$client->setAccessToken($accessToken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
}
return $client;
}
Please forgive my naiveté, but how is the script supposed to supply an auth code? Why is this step not performed?
</div>