我在尝试执行youtube analytics API时收到错误消息.
发生服务错误:调用GET时出错 https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUCaayLD9i5x4MmIoVZxXSv_g&start-date=2016-08-01&end-date=2016-08-07&metrics= views&dimensions = 7DayTotals:(403)禁止
这是我的代码:
require_once __DIR__.'\google-api-php-client-1-master\src\Google\autoload.php';
require_once __DIR__.'\google-api-php-client-1-master\src\Google\Client.php';
require_once __DIR__.'\google-api-php-client-1-master\src\Google\Service\YouTube.php';
session_start();
$key = file_get_contents('mykey.json');
$OAUTH2_CLIENT_ID = 'xx-xx-xx';
$OAUTH2_CLIENT_SECRET = 'xxx';
$scope = array("https://www.googleapis.com/auth/youtube.force-ssl", "https://www.googleapis.com/auth/youtubepartner-channel-audit", "https://www.googleapis.com/auth/youtube", "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/yt-analytics.readonly", "https://www.googleapis.com/auth/yt-analytics-monetary.readonly","https://www.googleapis.com/auth/youtubepartner");
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setAccessType('offline');
$client->setAccessToken($key);
$client->setScopes($scope);
if ($client->getAccessToken()) {
//Check to see if our access token has expired. If so, get a new one and save it to file for future use.
if($client->isAccessTokenExpired()) {
//refresh your access token if it's expired
$newToken = …Run Code Online (Sandbox Code Playgroud) 我想通过注意PHP中的夏令时将UTC时间转换为EST.这是我到目前为止所做的:
$from='UTC';
$to='EST';
$format='Y-m-d H:i:s';
$date=date('2106-03-15 23:00:00');// UTC time
date_default_timezone_set($from);
$newDatetime = strtotime($date);
date_default_timezone_set($to);
$newDatetime = date($format, $newDatetime);
date_default_timezone_set('UTC');
echo $newDatetime ;//EST time
Run Code Online (Sandbox Code Playgroud)
它正在回归6:00 AM EST,但由于夏令时它应该是7:00AM EST
任何的想法?