2013-01-31 125 views
5

我想从google +页面获取内容(帖子)并将其发布到我的网站上,作为feed。有什么信息如何?从google plus页面获取帖子

我读到目前的API不允许,但那些主题是从去年。

谢谢。

回答

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

+0

在当前谷歌php客户端中不包含此文件,,,,,,, Google_PlusService.php ,,,,,,, 从哪里可以得到完整的库? – Kiran

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 } ?> 
相关问题