2013-02-22 88 views

回答

3

根据您的确切需求,在https://developers.google.com/+/api/处记录的Google+ API可能会根据您的需要进行操作。它可以显示来自特定用户的公开帖子。您还可以在https://bakingdisasters.com/上看到一些示例代码。

但是,它不能做的是向您显示该用户允许的私人帖子,或者向您显示您可能看到的所有帖子(公共或私人)。

6

首先,您应该前往Google apis并启用Google Plus服务。它来了;

  1. 转至API Console
  2. 选择服务
  3. 启用Google+ API服务。
  4. 选择API访问
  5. 简单的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

enter image description here

4)用户id部分,输入您的个人资料ID并键入“大众”上收集部分依次执行。你可以在下面看到;

enter image description here