google calender apiを使ってみたく、下記記事のプログラムを実行してみましたが、ターミナルに何も出力されません。
https://qiita.com/yusuke-asaoka/items/c9eaa86968c4d5034801
以下私が実行したプログラムの全文になります。
PHP
1<?php 2require_once __DIR__ . '/vendor/autoload.php'; 3 4 5define('APPLICATION_NAME', 'yotei-kun'); 6define('CREDENTIALS_PATH', '~/.credentials/calendar-php-quickstart.json'); 7define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json'); 8// If modifying these scopes, delete your previously saved credentials 9// at ~/.credentials/calendar-php-quickstart.json 10define('SCOPES', implode(' ', array( 11 Google_Service_Calendar::CALENDAR_READONLY) 12)); 13 14if (php_sapi_name() != 'cli') { 15 throw new Exception('This application must be run on the command line.'); 16} 17 18/** 19 * Returns an authorized API client. 20 * @return Google_Client the authorized client object 21 */ 22function getClient() { 23 $client = new Google_Client(); 24 $client->setApplicationName(APPLICATION_NAME); 25 $client->setScopes(SCOPES); 26 $client->setAuthConfig(CLIENT_SECRET_PATH); 27 $client->setAccessType('offline'); 28 29 // Load previously authorized credentials from a file. 30 $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); 31 if (file_exists($credentialsPath)) { 32 $accessToken = json_decode(file_get_contents($credentialsPath), true); 33 } else { 34 // Request authorization from the user. 35 $authUrl = $client->createAuthUrl(); 36 printf("Open the following link in your browser:\n%s\n", $authUrl); 37 print 'Enter verification code: '; 38 $authCode = trim(fgets(STDIN)); 39 40 // Exchange authorization code for an access token. 41 $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); 42 43 // Store the credentials to disk. 44 if(!file_exists(dirname($credentialsPath))) { 45 mkdir(dirname($credentialsPath), 0700, true); 46 } 47 file_put_contents($credentialsPath, json_encode($accessToken)); 48 printf("Credentials saved to %s\n", $credentialsPath); 49 } 50 $client->setAccessToken($accessToken); 51 52 // Refresh the token if it's expired. 53 if ($client->isAccessTokenExpired()) { 54 $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); 55 file_put_contents($credentialsPath, json_encode($client->getAccessToken())); 56 } 57 return $client; 58} 59 60/** 61 * Expands the home directory alias '~' to the full path. 62 * @param string $path the path to expand. 63 * @return string the expanded path. 64 */ 65function expandHomeDirectory($path) { 66 $homeDirectory = getenv('HOME'); 67 if (empty($homeDirectory)) { 68 $homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH'); 69 } 70 return str_replace('~', realpath($homeDirectory), $path); 71} 72 73// Get the API client and construct the service object. 74var_dump(0); 75$client = getClient(); 76$service = new Google_Service_Calendar($client); 77 78// Print the next 10 events on the user's calendar. 79$calendarId = 'primary'; 80$optParams = array( 81 'maxResults' => 10, 82 'orderBy' => 'startTime', 83 'singleEvents' => TRUE, 84 'timeMin' => date('c'), 85); 86$results = $service->events->listEvents($calendarId, $optParams); 87 88if (count($results->getItems()) == 0) { 89 print "No upcoming events found.\n"; 90} else { 91 print "Upcoming events:\n"; 92 foreach ($results->getItems() as $event) { 93 $start = $event->start->dateTime; 94 if (empty($start)) { 95 $start = $event->start->date; 96 } 97 printf("%s (%s)\n", $event->getSummary(), $start); 98 } 99}
どこまで処理が実行されているのか確認したころgetClientメソッドの中の$client->createAuthUrl();という部分までのようでした。
認証情報のファイルはきちんとダウンロードして、CLIENT_SECRET_PATHの位置においてあります。
どなたか原因がわかる方、ご教授いただけないでしょうか。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/10 06:07