{"action":"created","issue":{"url":"https://api.github.com/repos/google/google-api-php-client/issues/504","labels_url":"https://api.github.com/repos/google/google-api-php-client/issues/504/labels{/name}","comments_url":"https://api.github.com/repos/google/google-api-php-client/issues/504/comments","events_url":"https://api.github.com/repos/google/google-api-php-client/issues/504/events","html_url":"https://github.com/google/google-api-php-client/issues/504","id":60582005,"number":504,"title":"Google Analytics API PHP Client","user":{"login":"Htaccess1993","id":6231117,"avatar_url":"https://avatars.githubusercontent.com/u/6231117?v=3","gravatar_id":"","url":"https://api.github.com/users/Htaccess1993","html_url":"https://github.com/Htaccess1993","followers_url":"https://api.github.com/users/Htaccess1993/followers","following_url":"https://api.github.com/users/Htaccess1993/following{/other_user}","gists_url":"https://api.github.com/users/Htaccess1993/gists{/gist_id}","starred_url":"https://api.github.com/users/Htaccess1993/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Htaccess1993/subscriptions","organizations_url":"https://api.github.com/users/Htaccess1993/orgs","repos_url":"https://api.github.com/users/Htaccess1993/repos","events_url":"https://api.github.com/users/Htaccess1993/events{/privacy}","received_events_url":"https://api.github.com/users/Htaccess1993/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-10T22:43:13Z","updated_at":"2015-03-26T02:17:59Z","closed_at":"2015-03-12T17:59:29Z","body":"Hello, i have many problems. I want to write an Google Analytics API PHP Client for generating Reports from analytics.\r\n\r\nWhy reports from Analytics?\r\nMonthly I want to check the visits on my website.\r\n\r\nCode\r\n```php\r\n<?php\r\n\r\n/**\r\n* Google Analytics API PHP Client\r\n* This Google Analytics API example works on the all-inkl.com Webhosting.\r\n* \r\n* @author Disrespector\r\n* @version 0.25\r\n* @licence Non-Free\r\n*/\r\n\r\nsession_start();\r\n\r\nrequire_once( $_SERVER['DOCUMENT_ROOT'] . 'google-api-php-client/src/Google/autoload.php');\r\nrequire_once( $_SERVER['DOCUMENT_ROOT'] . 'constants.php');\r\n\r\n$client = new Google_Client();\r\n$client->setApplicationName(APPLICATION_NAME);\r\n$client->setClientId(CLIENTID);\r\n$client->setClientSecret(CLIENTSECRET);\r\n$client->setRedirectUri(REDIRECTURI);\r\n$client->setDeveloperKey(DEVELOPERKEY);\r\n$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));\r\n\r\nif (isset($_GET['code'])) {\r\n  $client->authenticate( $_GET['code'] );\r\n  $_SESSION['token'] = $client->getAccessToken();\r\n  \r\n  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];\r\n  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));\r\n}\r\n\r\nif (isset($_SESSION['token'])) {\r\n  $client->setAccessToken($_SESSION['token']);\r\n}\r\n\r\nif (!$client->getAccessToken()) {\r\n\t$authUrl = $client->createAuthUrl();\r\n\tprint \"<a class='login' href='$authUrl'>Connect Me!</a>\";\r\n\texit;\r\n}\r\n\r\n$analytics = new Google_Service_Analytics( $client );\r\n$analytics_id = 'ga:' . TRACKINGID;\r\n\r\ndate_default_timezone_set('Europe/Berlin');\r\n$today = date(DATE_ATOM, strtotime('now'));\r\n$last = array(  'day'\t=> date(DATE_ATOM, strtotime('-24 hour')),\r\n\t\t\t\t'week'\t=> date(DATE_ATOM, strtotime('-7 day')),\r\n\t\t\t\t'month'\t=> date(DATE_ATOM, strtotime('-4 week')),\r\n\t\t\t\t'year'\t=> date(DATE_ATOM, strtotime('-52 week')));\r\n\r\ntry {\r\n\t$optParams = array();\r\n\t$metrics = 'ga:visits';\r\n\t\r\n\t$results = $analytics->data_ga->get($analytics_id,\r\n\t\t\t\t\t\t\t\t\t\t$last['week'],\r\n\t\t\t\t\t\t\t\t\t\t$today, $metrics, $optParams);\r\n\t\r\n\tprintf('<pre>%s</pre>', print_r($results, true));\r\n} catch(Exception $e) {\r\n\tprintf('<p>There was an Error in your query: %s</p>', $e->getMessage());\r\n}\r\n```\r\n\r\nI don't know what I can do. Please help me.\r\nThis is the Error Message:\r\n```\r\nThere was an Error in your query: Error calling GET https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3ATRACKINGID&start-date=2015-03-03T23%3A36%3A49%2B01%3A00&end-date=2015-03-10T23%3A36%3A49%2B01%3A00&metrics=ga%3Avisits&key=DEVELOPERKEY: (400) Invalid value '2015-03-10T23:36:49+01:00'. Values must match the following regular expression: '[0-9]{4}-[0-9]{2}-[0-9]{2}|today|yesterday|[0-9]+(daysAgo)'\r\n```\r\n\r\nOr when all is correct, i get this Error:\r\n```\r\nThere was an Error in your query: Error calling GET https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3ATRACKINGID&start-date=yesterday&end-date=today&metrics=ga%3Avisits&key=DEVELOPERKEY: (403) There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.\r\n```\r\n\r\n\r\nGreetz,\r\nDisrespector"},"comment":{"url":"https://api.github.com/repos/google/google-api-php-client/issues/comments/86296125","html_url":"https://github.com/google/google-api-php-client/issues/504#issuecomment-86296125","issue_url":"https://api.github.com/repos/google/google-api-php-client/issues/504","id":86296125,"user":{"login":"ianbarber","id":210006,"avatar_url":"https://avatars.githubusercontent.com/u/210006?v=3","gravatar_id":"","url":"https://api.github.com/users/ianbarber","html_url":"https://github.com/ianbarber","followers_url":"https://api.github.com/users/ianbarber/followers","following_url":"https://api.github.com/users/ianbarber/following{/other_user}","gists_url":"https://api.github.com/users/ianbarber/gists{/gist_id}","starred_url":"https://api.github.com/users/ianbarber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianbarber/subscriptions","organizations_url":"https://api.github.com/users/ianbarber/orgs","repos_url":"https://api.github.com/users/ianbarber/repos","events_url":"https://api.github.com/users/ianbarber/events{/privacy}","received_events_url":"https://api.github.com/users/ianbarber/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T02:17:59Z","updated_at":"2015-03-26T02:17:59Z","body":"You can check what range you have restricted the key to on the developer console at http://console.developers.google.com"}}