【发布时间】:2013-11-16 10:31:31
【问题描述】:
我想使用 php 将我的 google plus 帐户链接到我的网站,以便显示来自我的 google plus 帐户的帖子(无需经过认证过程)。这可行吗,如果是我应该使用什么google api?
问候
【问题讨论】:
-
请阅读How to Ask 以改进您的问题。
标签: php google-plus google-authentication
我想使用 php 将我的 google plus 帐户链接到我的网站,以便显示来自我的 google plus 帐户的帖子(无需经过认证过程)。这可行吗,如果是我应该使用什么google api?
问候
【问题讨论】:
标签: php google-plus google-authentication
您只能检索任何帐户的公开帖子。广泛的答案是,您可以作为未经身份验证的应用程序对 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());
上面的示例将检索拉里佩奇公开帖子的第一页。
【讨论】: