Can't get simple google client API example .php

Just trying to use the Google Client API to carry traffic data for my site and thought I'd try the simple.php file at https://code.google.com/p/google-api-php-client/source/browse/trunk/examples /contacts/simple.php

I edited it appropriately for my credentials and I can get it to go from the "Connect me" link to the request permission page, but after I agree, I end up with "This web page is not available". I am wondering if there might be a problem with the need to update the token?

Any thoughts are greatly appreciated. Thank!

<?php
require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_AnalyticsService.php';
session_start();

$client = new Google_Client();
$client->setApplicationName("Google Analytics PHP Starter Application");

// Visit https://code.google.com/apis/console?api=analytics to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('MY_CLIENT_ID');
$client->setClientSecret('MY_CLIENT_SECRET');
$client->setDeveloperKey('MY_DEVELOPER_KEY');
$client->setRedirectUri('http://localhost/google-analytics/simple.php');
$service = new Google_AnalyticsService($client);

if (isset($_GET['logout'])) {
  unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
  $client->authenticate();
  $_SESSION['token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['token'])) {
  $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
  $props = $service->management_webproperties->listManagementWebproperties("~all");
  print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";

  $accounts = $service->management_accounts->listManagementAccounts();
  print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
  $segments = $service->management_segments->listManagementSegments();
  print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
  $goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
  print "<h1>Segments</h1><pre>" . print_r($goals, true) . "</pre>";
  $_SESSION['token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();
  print "<a class='login' href='$authUrl'>Connect Me!</a>";
}

      

+3
php google-client


source to share


No one has answered this question yet

Check out similar questions:

2263
How to get YouTube video thumbnail using YouTube API?
1085
How to get client IP address in PHP
five
Pure Magento Google Api OAuth2 Integration
4
Google Service PHP Account Authentication
3
Authenticate google service account with google-api-php-client using calendar api
2
Google Calendar API, Google_Service class
1
Moving to Google Fusion Tables in Google API V.1
1
Google API PHP Client cannot get contacts
1
how to login and get analytics event data using php
0
Google_Auth_Exception While trying to get OAuth 2.0 service account authentication



All Articles
Loading...
X
Show
Funny
Dev
Pics