I am trying to get the organizations from a user with Google+ API or Google+ Domains API. I am following the steps on the official documentation and the logic I'm using is this one:
<?php session_start();
require_once 'vendor/autoload.php'; //INCLUDE PHP CLIENT LIBRARY
$scopes = array(
"https://www.googleapis.com/auth/plus.profiles.read",
"https://www.googleapis.com/auth/plus.me"
);
// Create client object and set its configuraitons
$client = new Google_Client();
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/');
$client->setAuthConfig("creds.json");
$client->addScope($scopes);
if( isset($_SESSION["access_token"]) ) {
$client->setAccessToken($_SESSION["access_token"]);
$service = new Google_Service_PlusDomains($client);
$me = $service->people->get('me');
var_dump($me);
echo "<br><br>*********************************************<br><br>";
$orgs = $me->getOrganizations(); // (THIS IS EMPTY!!!) ????
var_dump($orgs);
} else {
if( !isset($_GET["code"]) ){
$authUrl = $client->createAuthUrl();
header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
}
?>
This perfectly works for G-Suite account I had before the transition of Google+ to Google+ Domains. When I use this same script on a newer G Suite account, it won't work. I have tried with $service = new Google_Service_Plus($client);
and the result is the same thing. Any idea why it won't work with newer G Suite accounts? Is anybody else having the same issue?
Ok. I found the root cause of my problem. It happens that the User Resource and the People Resource are two different resources. Both of them have the "organization" attribute but the information of the user resource will not appear in your Google Plus profile and in order to populate the "organization" attribute of the people resource, the user is required to manually update the information from the "about me" page in Google Plus. At the moment, seems there is no way to programmatically update the information of the People Resource but users have to do it manually.