<?php

require ___DIR___ . "/vendor/autoload.php";

$client = new Google\Client;

$client->setClientId("538988573742-oie0ranrq1j42ekcgo4comncstd7jaf8.apps.googleusercontent.com");
$client->setClientSecret("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");
$client->setRedirectUri('http://localhost/StreetPasta/7account.php');

if (! isset($_GET["code"])) {

  exit("Login failed");
}
$token = $client->fetchAccessTokenWithAuthCode($_GET["code"]);

$client->setAccessToken($token["access_token"]);

$oauth = new Google\Service\Oauth2($client);

$userinfo = $oauth->userinfo->get();

var_dump(
  $userinfo->email,
  $userinfo->name,
  $userinfo->givenName,
  $userinfo->familyName,
  $userinfo->picture,
  $userinfo->locale
);
