0

我正在尝试使用 Google+ API 或 Google+ Domains API 从用户那里获取组织。我正在按照官方文档中的步骤进行操作,我使用的逻辑是这样的:

<?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));

    }
}

?>

这非常适用于我在将 Google+ 转换为 Google+ Domains 之前拥有的 G - Suite帐户。当我在较新的 G Suite 帐户上使用相同的脚本时,它不起作用。我试过了$service = new Google_Service_Plus($client);,结果是一样的。知道为什么它不适用于较新的 G Suite 帐户吗?其他人有同样的问题吗?

4

1 回答 1

0

好的。我找到了问题的根本原因。碰巧用户资源人员资源是两种不同的资源。它们都具有“组织”属性,但用户资源的信息不会出现在您的 Google Plus 个人资料中,为了填充人员资源的“组织”属性,用户需要手动更新来自Google Plus 中的“关于我”页面。目前,似乎没有办法以编程方式更新人员资源的信息,但用户必须手动进行。

于 2017-01-27T16:06:53.133 回答