• <i id='bfIZQ'><tr id='bfIZQ'><dt id='bfIZQ'><q id='bfIZQ'><span id='bfIZQ'><b id='bfIZQ'><form id='bfIZQ'><ins id='bfIZQ'></ins><ul id='bfIZQ'></ul><sub id='bfIZQ'></sub></form><legend id='bfIZQ'></legend><bdo id='bfIZQ'><pre id='bfIZQ'><center id='bfIZQ'></center></pre></bdo></b><th id='bfIZQ'></th></span></q></dt></tr></i><div id='bfIZQ'><tfoot id='bfIZQ'></tfoot><dl id='bfIZQ'><fieldset id='bfIZQ'></fieldset></dl></div>
  • <small id='bfIZQ'></small><noframes id='bfIZQ'>

  • <tfoot id='bfIZQ'></tfoot>

      <legend id='bfIZQ'><style id='bfIZQ'><dir id='bfIZQ'><q id='bfIZQ'></q></dir></style></legend>

        <bdo id='bfIZQ'></bdo><ul id='bfIZQ'></ul>

        通过 api 发布到 google plus

        时间:2023-07-14

        1. <tfoot id='9IB3S'></tfoot>

          <legend id='9IB3S'><style id='9IB3S'><dir id='9IB3S'><q id='9IB3S'></q></dir></style></legend>
          • <bdo id='9IB3S'></bdo><ul id='9IB3S'></ul>

                <tbody id='9IB3S'></tbody>

                  <i id='9IB3S'><tr id='9IB3S'><dt id='9IB3S'><q id='9IB3S'><span id='9IB3S'><b id='9IB3S'><form id='9IB3S'><ins id='9IB3S'></ins><ul id='9IB3S'></ul><sub id='9IB3S'></sub></form><legend id='9IB3S'></legend><bdo id='9IB3S'><pre id='9IB3S'><center id='9IB3S'></center></pre></bdo></b><th id='9IB3S'></th></span></q></dt></tr></i><div id='9IB3S'><tfoot id='9IB3S'></tfoot><dl id='9IB3S'><fieldset id='9IB3S'></fieldset></dl></div>

                  <small id='9IB3S'></small><noframes id='9IB3S'>

                  本文介绍了通过 api 发布到 google plus的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  试图找到如何从 PHP 发布到 google plus 墙,但即使使用 api 资源管理器也得到 403 at 得到了

                  Trying to find how to post to google plus wall from PHP but got 403 even using the api explorer at got the

                  {
                   "error": {
                    "errors": [
                     {
                      "domain": "global",
                      "reason": "forbidden",
                      "message": "Forbidden"
                     }
                    ],
                    "code": 403,
                    "message": "Forbidden"
                   }
                  }
                  

                  我的 PHP 代码如下:

                  My PHP code looks like:

                      $client = new Google_Client();
                      $client->setApplicationName("Speerit");
                      $client->setClientId($appId);
                      $client->setClientSecret($appSecret);
                      $client->setAccessType("offline");        // offline access
                      $client->setIncludeGrantedScopes(true);   // incremental auth
                      $client->setAccessToken(
                          json_encode(
                              array(
                                  'access_token' => $accessToken,
                                  'expires_in' => 3600,
                                  'token_type' => 'Bearer',
                              )
                          )
                      );
                      $client->setScopes(
                          array(
                              "https://www.googleapis.com/auth/userinfo.email",
                              "https://www.googleapis.com/auth/plus.me",
                              "https://www.googleapis.com/auth/plus.stream.write",
                          )
                      );
                      $client = $client->authorize();
                  
                      // create the URL for this user ID
                      $url = sprintf('https://www.googleapis.com/plusDomains/v1/people/me/activities');
                  
                      // create your HTTP request object
                      $headers = ['content-type' => 'application/json'];
                      $body = [
                          "object" => [
                              "originalContent" => "Happy Monday! #caseofthemondays",
                          ],
                          "access" => [
                              "items" => [
                                  ["type" => "domain"],
                              ],
                              "domainRestricted" => true,
                          ],
                      ];
                      $request = new Request('POST', $url, $headers, json_encode($body));
                  
                      // make the HTTP request
                      $response = $client->send($request);
                  
                      // did it work??
                      echo $response->getStatusCode().PHP_EOL;
                      echo $response->getReasonPhrase().PHP_EOL;
                      echo $response->getBody().PHP_EOL;
                  

                  遵循官方文档和其他帖子的一些参考

                  Following official documentation and some references from other posts

                  推荐答案

                  首先,我们需要了解有一个免费的 google 帐户的 API,意思是帐户结尾是 @gmail.com 并且有用于 G Suite 帐户的 API,意思是帐户结尾为 @yourdomain.com. 基于 参考文档 和最近的测试,无法在免费谷歌帐户上使用 API 插入评论(@gmail.com).

                  First, we need to understand that there is an API for free google accounts, meaning accounts ending @gmail.com and there is an API for G Suite accounts, meaning account ending @yourdomain.com. Based on the reference documentation and recent testings, it is not possible to insert a comment using the API on free google accounts (@gmail.com).

                  这仅适用于 G Suite 帐户(@yourdomain.com).我必须阅读插入方法,我能够通过执行以下操作使其工作:

                  This is only possible with G Suite accounts (@yourdomain.com). I had to read the documentation for the insert method, and I was able to make it work by doing the following:

                  <?php session_start();
                  
                  require_once "vendor/autoload.php"; //include library
                  
                  //define scopes required to make the api call
                      $scopes = array(
                    "https://www.googleapis.com/auth/plus.stream.write",
                    "https://www.googleapis.com/auth/plus.me"
                  );
                  
                  // Create client object
                  $client = new Google_Client(); 
                  $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/index.php');
                  $client->setAuthConfig("client_secret.json");
                  $client->addScope($scopes);
                  
                  if( isset($_SESSION["access_token"]) ) {
                  
                    $client->setAccessToken($_SESSION["access_token"]);
                    $service = new Google_Service_PlusDomains($client);
                  
                    $activity = new Google_Service_PlusDomains_Activity(
                      array(
                        'access' => array(
                            'items' => array(
                                'type' => 'domain'
                            ),
                            'domainRestricted' => true
                        ),
                        'verb' => 'post',
                        'object' => array(
                            'originalContent' => "Post using Google API PHP Client Library!" 
                        ), 
                      )
                    );
                  
                    $newActivity = $service->activities->insert("me", $activity);
                  
                  
                    var_dump($newActivity);
                  
                  
                  } 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'] . '/index.php';
                        header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
                  
                    }
                  }
                  
                  ?>
                  

                  总而言之,如果您尝试在免费的 gmail.com 帐户上执行此操作,您将收到 403 Forbidden 错误.希望将来可以使用此功能,但就目前而言,只有与 Google 合作的公司才能访问此特殊 API,例如 Hootsuite.

                  In summary, if you try to do this on a free gmail.com account, you will get the 403 Forbidden error. Hopefully in the future this will be available but for right now, only companies that have partnered with Google has access to this special api, such as Hootsuite.

                  这篇关于通过 api 发布到 google plus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 PHP 中访问 Google 电子表格 API? 下一篇:允许我的用户使用带有 PHP 的 Google Calendar API 在我的日历中添加会议,无需身份验证

                  相关文章

                      <bdo id='UXwTl'></bdo><ul id='UXwTl'></ul>

                      <small id='UXwTl'></small><noframes id='UXwTl'>

                      <i id='UXwTl'><tr id='UXwTl'><dt id='UXwTl'><q id='UXwTl'><span id='UXwTl'><b id='UXwTl'><form id='UXwTl'><ins id='UXwTl'></ins><ul id='UXwTl'></ul><sub id='UXwTl'></sub></form><legend id='UXwTl'></legend><bdo id='UXwTl'><pre id='UXwTl'><center id='UXwTl'></center></pre></bdo></b><th id='UXwTl'></th></span></q></dt></tr></i><div id='UXwTl'><tfoot id='UXwTl'></tfoot><dl id='UXwTl'><fieldset id='UXwTl'></fieldset></dl></div>

                    1. <legend id='UXwTl'><style id='UXwTl'><dir id='UXwTl'><q id='UXwTl'></q></dir></style></legend><tfoot id='UXwTl'></tfoot>