【问题标题】:Search google+ api for public posts and pages在 google+ api 中搜索公开帖子和页面
【发布时间】:2012-09-26 15:44:24
【问题描述】:

我正在尝试将 google-api-php-client SDK 与 google plus api 服务一起使用。文档不是很清楚。我搜索活动吗?我是否需要获得 oAuth 令牌才能做我想做的事?

更新:现在使用

    $params = array(
              'orderBy' => 'best',
              'maxResults' => '20',
              'query' => 'Google+ API'
            );

   $results = $plus->activities->search($params);

返回

    Array
(
    [kind] => plus#activityFeed
    [etag] => "5NTCbsXue5u92XtxuV0QeM_x9B4/58mHUy-IErItGIABIAhYhhUjJ-M"
    [selfLink] => https://www.googleapis.com/plus/v1/activities?query&maxResults=10
    [title] => Plus Search
    [updated] => 2012-09-27T14:03:35.132Z
    [id] => tag:google.com,2010:es-search-feed:z80ghJXVZe9m59_5-Ydk2g
    [items] => Array
        (
        )

)

【问题讨论】:

    标签: php google-api google-plus


    【解决方案1】:

    我遇到了同样的问题,我是这样做的:

    $query = "some query";    
    $params = array(
          'orderBy' => 'best',
          'maxResults' => '20',
    );
    
    $results = $plus->activities->search($query, $params);
    foreach($results['items'] as $result) {
          print "Result: {$result['object']['content']}\n";
    }
    

    即使是示例查询中的面团也是参数的一部分,但它不是。它应该作为分隔值发送,如您在 plus 服务 Link 的搜索方法的实现中所见

    希望对你有所帮助。

    【讨论】:

      【解决方案2】:

      您不需要 OAuth 令牌来搜索活动。您只需在 Google API 控制台中注册一个开发者密钥。

      1. Google APIs Console 中注册开发者密钥。
      2. 查看Google APIs PHP Client 的最新版本。
      3. 查看 Google+ 示例应用程序。 https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/plus/index.php

      示例:

      $params = array(
        'orderBy' => 'best',
        'maxResults' => '20',
        'query' => 'Google+ API'
      );
      
      $results = $plus->activities->search($params);
      foreach($results['items'] as $result) {
        print "Result: {$result['object']['content']}\n";
      }
      

      【讨论】:

      • 我没有返回任何结果。用返回的内容更新了问题。还会收到警告:rawurlencode() 期望参数 1 为字符串,数组给定 googleplus/google-api-php-client/src/io/apiREST.php,第 129 行]
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多