从谷歌加页面获取帖子

时间:2013-01-31 10:22:41

标签: api rss feed google-plus

我想从google +页面获取内容(帖子)并将其作为Feed发布到我的网站。有没有信息怎么样?

我读到当前的API不允许这样做,但这些主题来自去年。

感谢。

3 个答案:

答案 0 :(得分:10)

您可以执行activities.list,无需进行身份验证,方法是将API console中的“简单”密钥传递给已启用Google+服务的项目。对API调用的访问仅限于您在项目中设置的授权来源。

创建项目后,在“简单API访问”部分中有一个API密钥。使用此密钥,您的客户端ID和客户端密钥构建您的客户端:

<?
    $client = new Google_Client();
    $client->setDeveloperKey("YOUR_API_KEY");
    $plus = new Google_PlusService($client);
    $activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>
<html><body><pre><? echo print_r($activities);?></pre></body></html>

最后一点,请务必使用latest Google+ PHP client

答案 1 :(得分:2)

过了一段时间我找到了它。

http://code.google.com/p/google-plus-php-starter/

和这个

https://developers.google.com/+/api/latest/activities/list

唯一的问题是您需要登录谷歌应用才能执行此操作。任何建议都会得到赞赏。

答案 2 :(得分:2)

更新正确答案后,班级名称已更改为Google_Service_Plus

<?php
    set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
    require_once __DIR__.'/vendor/autoload.php';

    $client = new Google_Client();
    $client->setDeveloperKey("YOUR_API_KEY");
    $plus = new Google_Service_Plus($client);
    $activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>

$items = $activities->getItems();
foreach($items as $item) {

   $object = $item->getObject();
?>

<div class="gpost">
   <p><?php echo $object->getContent(); ?></p>
   <a href="<?php echo $item['url']; ?>">Read more</a>
</div>

<?php } ?>
相关问题