title: Google Analytics API Automated Login
body: <p>I have this panel that i'm developing at my company where i will show the user's information from Google Analytics but i don't want the user to authorize or log in with his account every time he comes to the panel.</p>
  
  <p>What i would like to do is: on the first time using my panel he would connect his Google account and i would save some info and on the next time he connects at my panel i would use this saved info to log on his account so i can list the Analytics info without ask for his permission or list that info even if he's not connected on is Google account right now.</p>
  
  <p>Basically i would log in his account automatically and permit the 'app' to show the information.</p>
  
  <p>I already have some code that connects on the API if he is connected on is Google account, but when he's not i get the login screen where he has to provide his email e password.</p>
  
  <p>What i have so far is this:</p>
  
  <pre><code>&lt;?php
  require_once 'Google/Client.php';
  require_once 'Google/Service/Analytics.php';
  
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Google Analytics PHP Starter Application");
  
  $client-&gt;setClientId('KEY');
  $client-&gt;setClientSecret('SECRET');
  $client-&gt;setRedirectUri('RETURN URI');
  $client-&gt;setScopes('https://www.googleapis.com/auth/analytics.readonly');
  $client-&gt;setAccessType('offline');
  $service = new Google_Service_Analytics($client);
  
  if(isset($_GET['logout']))
  {
    unset($_SESSION['token']);
  }
  
  if(isset($_GET['code']))
  {
    $client-&gt;authenticate($_GET['code']);
    $_SESSION['token'] = $client-&gt;getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
  }
  
  if(isset($_SESSION['token']))
  {
    $client-&gt;setAccessToken($_SESSION['token']);
  }
  
  if($client-&gt;getAccessToken())
  {
    $props = $service-&gt;management_webproperties-&gt;listManagementWebproperties("12008145");//~all
    print "&lt;h1&gt;Web Properties&lt;/h1&gt;&lt;pre&gt;" . print_r($props, true) . "&lt;/pre&gt;";
  
    $accounts = $service-&gt;management_accounts-&gt;listManagementAccounts();
    //print "&lt;h1&gt;Accounts&lt;/h1&gt;&lt;pre&gt;" . print_r($accounts, true) . "&lt;/pre&gt;";
  
    $segments = $service-&gt;management_segments-&gt;listManagementSegments();
    //print "&lt;h1&gt;Segments&lt;/h1&gt;&lt;pre&gt;" . print_r($segments, true) . "&lt;/pre&gt;";
  
    $goals = $service-&gt;management_goals-&gt;listManagementGoals("~all", "~all", "~all");
    //print "&lt;h1&gt;Goals&lt;/h1&gt;&lt;pre&gt;" . print_r($goals, true) . "&lt;/pre&gt;";
  
    $_SESSION['token'] = $client-&gt;getAccessToken();
  }
  else
  {
    $authUrl = $client-&gt;createAuthUrl();
    header("Location: " . $authUrl);
  }
  ?&gt;
  </code></pre>
  
  <p>Is there any way to do that ? I have looked for it around everywhere and couldn't find something near it.</p>