2013-01-31 126 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 } ?> 
相關問題