【问题标题】:Connect automatically to a Google Plus Account自动连接到 Google Plus 帐户
【发布时间】:2013-11-16 10:31:31
【问题描述】:

我想使用 php 将我的 google plus 帐户链接到我的网站,以便显示来自我的 google plus 帐户的帖子(无需经过认证过程)。这可行吗,如果是我应该使用什么google api?

问候

【问题讨论】:

标签: php google-plus google-authentication


【解决方案1】:

您只能检索任何帐户的公开帖子。广泛的答案是,您可以作为未经身份验证的应用程序对 activities.list API 方法执行 API 调用,并且可以检索具有特定用户 ID(1xxxxxxxxxxx 而不是“我”)的用户的公共帖子。

您可以使用Google Client library for PHP 来简化请求。假设您有一个完全连接的Google_client 对象和一个实例化的Google_PlusService,您可以调用:

$client = new Google_Client();
$client->setApplicationName('My Google+ PHP App');
// Visit https://code.google.com/apis/console?api=plus to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$client->setDeveloperKey('insert_your_simple_api_key');
$plus = new Google_PlusService($client);
$posts = $plus->activities->listActivities('106189723444098348646', 'public', array());

上面的示例将检索拉里佩奇公开帖子的第一页。

【讨论】:

  • 感谢您的回复!我通过替换我的参数来尝试您的代码,但我有一个错误致命错误:无法在 C:\wamp\www\google-api-php-client-0.6.7\google-api-php-client\src 中取消设置字符串偏移量\service\Google_ServiceResource.php 第 95 行
  • 终于成功了。我将 $plus->activities->list 替换为 $plus->activities->listActivities 并且效果很好!再次感谢!
猜你喜欢
  • 1970-01-01
  • 2021-10-05
  • 2013-05-25
  • 1970-01-01
  • 1970-01-01
  • 2019-07-24
  • 2021-11-30
  • 2013-01-15
  • 2014-12-13
相关资源
最近更新 更多