如何从Google +流中获取帖子
问题描述:
我需要从流中获取Google +帖子并将其发布到我的网站上。我知道谷歌没有API来做到这一点。但一些服务,如吸http://www.friendsplus.me/可以做到这一点。有人知道如何?如何从Google +流中获取帖子
答
根据您的确切需求,在https://developers.google.com/+/api/处记录的Google+ API可能会根据您的需要进行操作。它可以显示来自特定用户的公开帖子。您还可以在https://bakingdisasters.com/上看到一些示例代码。
但是,它不能做的是向您显示该用户允许的私人帖子,或者向您显示您可能看到的所有帖子(公共或私人)。
答
首先,您应该前往Google apis并启用Google Plus服务。它来了;
- 转至API Console。
- 选择服务
- 启用Google+ API服务。
- 选择API访问
- 简单的API访问>获取您的API密钥。
您可以使用以下代码读取流的帖子;
<?php
$google_plus_id = '106670447018211124292';
$appKey = 'app_key_here';
$streams = json_decode(file_get_contents('https://www.googleapis.com/plus/v1/people/' . $google_plus_id . '/activities/public?key='. $appKey));
foreach ($streams->items as $item) {
echo $item->title .
date('F jS Y @ H:i:s',strtotime($item->published)) .
$item->object->content .
'<br />';
}
您也可以在google api控制台上测试此代码的工作。
1)转到API Console并选择Google+的API
2)选择的API菜单左侧的菜单上
3)点击public.activities.list on the page
4)在用户id部分,输入您的个人资料ID并键入“大众”上收集部分依次执行。你可以在下面看到;