I am trying to login through Google API and getting access to some of the user data, including birthday.
This is the code and scopes I am using:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
const CLIENT_ID = '[MY CLIENT ID]';
const CLIENT_SECRET = '[MY APP SECRET]';
const APPLICATION_NAME = "Google+ PHP Quickstart";
$client = new Google_Client();
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->addScope('https://www.googleapis.com/auth/plus.login');
$client->addScope('https://www.googleapis.com/auth/user.birthday.read');
$client->addScope('https://www.googleapis.com/auth/userinfo.email');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile');
$client->addScope('https://www.googleapis.com/auth/plus.me');
$client->setRedirectUri('https://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
When I see the login screen, I am asked to allow the app to access my birthday, as you can see below (it is in portuguese but it mentions birth date!).
Nonetheless, I cannot get access to the birthday nor the date.
This is what I use to get user info on the callback page:
$objOAuthService = new Google_Service_Oauth2($client);
if ($client->getAccessToken()) {
$userData = $objOAuthService->userinfo->get();
print_r($userData);
}
What am I missing?
I saw an answer regarding public or private visibility of the birthdate, but it seemed a strange requirement. Why does it ask the user if he allows the birthday to be shown, the user says yes, and it is not returned to the site as it is not public? I would like some official google source document stating this, instead of an answer without any official references, so I would like someone to shed some light on this with any strong information to back this up.