使用谷歌API获取谷歌帐户图像

At the very first time,I'm trying to get my google account profile picture by using google api. So I have referred Refer this site.

so in my google-plus-access.php:

   <?php

    require_once 'google-api-php-client-master/src/Google/autoload.php'; // or wherever autoload.php is located

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

    $client->setClientId('MY_CLIENT_ID');
    $client->setClientSecret('MY_SECRET_KEY');
    $client->setRedirectUri('http://localhost/G-api');
    $client->setDeveloperKey('MY_DEV_KEY');

    $client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
    //$plus = new apiPlusService($client);
    $plus = $client -> createAuthUrl();
    if(isset($_REQUEST['logout']))
    {
        unset($_SESSION['access_token']);
    }

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

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

    if ($client->getAccessToken()) {
      $me = $plus->people->get('me');
      echo $me;
      $optParams = array('maxResults' => 100);
      $activities = $plus->activities->listActivities('me', 'public', $optParams);

      $_SESSION['access_token'] = $client->getAccessToken();
    } else {
      $authUrl = $client->createAuthUrl();
      echo '<pre>';
      print_r($authUrl); // this block is running!!!
      echo '</pre>';
    }
    echo "</br>";

?>

And in my index.php:

  <?php
     include('google-plus-access.php');
  ?>
   <img src="<?php  echo(substr($me['image']['url'],0,stripos($me['image']['url'],'?sz='))); ?>?sz=200" />

but i'm getting the result as:

   https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2FG-api&client_id=887633147241-8ragvhdi97lga3n829qogpl5aoima7l5.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me&access_type=online&approval_prompt=auto

In my console I'm getting the below error: enter image description here

My output scree is looking like this :

enter image description here

EDIT:

In my console i'm getting GET http://localhost/G-api/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20…/G-api/index.php%3C/b%3E%20on%20line%20%3Cb%3E7%3C/b%3E%3Cbr%20/%3E?sz=200 403 (Forbidden) this.

These things are done in local.So some body making me scared that we can't do this is local and we have create domain for that.So kindly help me to do this.

Check your code $me is created in the if // this block is running!!! is in the else.

You are trying to use $me which hasn't been created.

if ($client->getAccessToken()) {
      $me = $plus->people->get('me');   //Daimto: This doesn't run so you cant use it
      echo $me;
      $optParams = array('maxResults' => 100);
      $activities = $plus->activities->listActivities('me', 'public', $optParams);

      $_SESSION['access_token'] = $client->getAccessToken();
} else {
      $authUrl = $client->createAuthUrl();
      echo '<pre>';
      print_r($authUrl); // this block is running!!!
      echo '</pre>';
}

You also need to create a service, $plus->people->get('me'); isn't going to work because $plus isn't a Google_Service_Plus. You should check out the example found here user-sample.php

$googlePlus = new Google_Service_Plus($client);
$userProfile = $googlePlus->people->get('me');