Google+如何将消息发布到我的页面?谷歌api php客户端

Google+如何将消息发布到我的页面?谷歌api php客户端,php,google-api-php-client,Php,Google Api Php Client,我不会从我的网站向我的google+页面发布消息。试试简单的例子 我的代码是: <?php require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located $client_id = '-'; $client_secret = '-'; $redirect_uri = 'redirect_uri'; $client = new Go

我不会从我的网站向我的google+页面发布消息。试试简单的例子

我的代码是:

<?php 
    require_once 'google-api-php-client/autoload.php'; // or wherever autoload.php is located

    $client_id = '-';
    $client_secret = '-';
    $redirect_uri = 'redirect_uri';

    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);

    $client->setAccessType('offline');
    $client->setScopes(array('https://www.googleapis.com/auth/plus.login'));

    $client->setRequestVisibleActions(array('https://schemas.google.com/AddActivity'));
    $client->setApprovalPrompt('force');

    if (isset($_REQUEST['logout'])) {
      unset($_SESSION['access_token']);
    }

    if (isset($_GET['code'])) {
      $client->authenticate($_GET['code']);
      $_SESSION['access_token'] = $client->getAccessToken();
    }

    /************************************************
      If we have an access token, we can make
      requests, else we generate an authentication URL.
     ************************************************/
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
      $client->setAccessToken($_SESSION['access_token']);
    } else {
      $authUrl = $client->createAuthUrl();
    }

    if ($client->getAccessToken()) {


        $plusService = new Google_Service_Plus($client);

        //$userinfo=$plusService->people->get('me');
        //print_r($userinfo);
        $moment_body = new Google_Service_Plus_Moment();
        $moment_body->setType("http://schemas.google.com/AddActivity");

        $item_scope = new Google_Service_Plus_ItemScope();
        $item_scope->setId("target-id-1");
        $item_scope->setType("http://schemas.google.com/AddActivity");
        $item_scope->setName("The Google+ Platform");
        $item_scope->setDescription("A page that describes just how awesome Google+ is!");
        $item_scope->setImage("https://developers.google.com/+/plugins/snippet/examples/thing.png");

        $moment_body->setTarget($item_scope);
        $momentResult = $plusService->moments->insert('me', 'vault', $moment_body, array("debug"=>true));
        //print_r($momentResult);

        $_SESSION['access_token'] = $client->getAccessToken();
    }

    if (
        $client_id == '<YOUR_CLIENT_ID>'
        || $client_secret == '<YOUR_CLIENT_SECRET>'
        || $redirect_uri == '<YOUR_REDIRECT_URI>') {
      echo missingClientSecretsWarning();
    }
    echo 
    '<div class="box">
      <div class="request">';

    if (isset($authUrl)) {
      echo "<a class='login' href='" . $authUrl . "'>Connect Me!</a>";
    } else {
      echo '
        <a class="logout" href="?logout">Logout</a>';
    }
     echo "</div>

      <div class='shortened'>";
    if (isset($momentResult)) {
      var_dump($momentResult);
    }

     echo " </div>
    </div>";
但它不起作用。我没有犯任何错误。只是我瞬间的空虚阵列

objectGoogle\u服务\u Plus\u时刻19 13{[internal\u gapi\u mappings:protected]=>array0{}[id]=>NULL[kind]=>string11 plusmoment[objectType:protected]=>string29 Google\u服务\u Plus\u项目范围[objectDataType:protected]=>string0[resultType:protected]=>string29 Google\u服务\u项目范围[resultDataType:protected]=>string0[startDate]=>NULL[targetType:protected]=>string29谷歌服务加上项目范围[targetDataType:protected]=>string0[type]=>string37…[modelData:protected]=>array1{[target]=>array6{[kind]=>string14 plusitemScope[type]=>string37[id]=>string11 target-id-1[description]=>string50一个描述Google+有多棒的页面![image]=>string66 fhg[name]=>string20 Google+平台}}[processed:protected]=>array0{}


希望你能告诉我哪里出了错。Thx.

我认为您需要这样做来发布$client->setRequestVisibleActions。。。但是请记住,你不能用Google+API发布你的时间线。瞬间不是一回事。所以我应该用另一种方法,而不是瞬间?用Google+API发布你的Google+时间线是不可能的。没有其他方法。