从Google+信息页获取所有活动并访问内容

时间:2015-03-20 09:49:30

标签: php arrays api object google-plus

我正在尝试使用Google PHP Api Client从G +页面获取所有活动:

$service = new \Google_Service_Plus($this->client);
    $activities = $service->activities->listActivities($data['page_id'], 'public');

结果是Google_Service_Plus_Activity个对象的数组。问题是,我想访问其中一个活动的内容以搜索字符串,但这是["modelData":protected]=> array(1) ["content"]=> string(int) "my_string"下的var_dump($activity)。是否有可能访问内容?

object(Google_Service_Plus_Activity)#268 (28) { ["internal_gapi_mappings":protected]=> array(0) { } ["accessType":protected]=> string(23) "Google_Service_Plus_Acl" ["accessDataType":protected]=> string(0) "" ["actorType":protected]=> string(33) "Google_Service_Plus_ActivityActor" ["actorDataType":protected]=> string(0) "" ["address"]=> NULL ["annotation"]=> NULL ["crosspostSource"]=> NULL ["etag"]=> string(57) ""RqKWnRU4WW46-6W3rWhLR9iFZQM/t4CM2-QFWMd8gXogVxXGqNUhGSA"" ["geocode"]=> NULL ["id"]=> string(35) "z133dxyyhuaqf5tqd04cebxrtuykyfc5vi0" ["kind"]=> string(13) "plus#activity" ["locationType":protected]=> string(25) "Google_Service_Plus_Place" ["locationDataType":protected]=> string(0) "" ["objectType":protected]=> string(34) "Google_Service_Plus_ActivityObject" ["objectDataType":protected]=> string(0) "" ["placeId"]=> NULL ["placeName"]=> NULL ["providerType":protected]=> string(36) "Google_Service_Plus_ActivityProvider" ["providerDataType":protected]=> string(0) "" ["published"]=> string(24) "2015-03-20T09:03:51.236Z" ["radius"]=> NULL ["title"]=> string(103) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=017f5b8e-cee0..." ["updated"]=> string(24) "2015-03-20T09:03:51.236Z" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/akiK7Yx6eus" ["verb"]=> string(4) "post" ["modelData":protected]=> array(4) { ["actor"]=> array(4) { ["id"]=> string(21) "104620991895987671420" ["displayName"]=> string(27) "Magazin de scule barbatesti" ["url"]=> string(45) "https://plus.google.com/104620991895987671420" ["image"]=> array(1) { ["url"]=> string(98) "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50" } } ["object"]=> array(6) { ["objectType"]=> string(4) "note" ["content"]=> string(264) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=017f5b8e-cee0-11e4-8698-448a5b89d5f1" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/akiK7Yx6eus" ["replies"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(90) "https://www.googleapis.com/plus/v1/activities/z133dxyyhuaqf5tqd04cebxrtuykyfc5vi0/comments" } ["plusoners"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(98) "https://www.googleapis.com/plus/v1/activities/z133dxyyhuaqf5tqd04cebxrtuykyfc5vi0/people/plusoners" } ["resharers"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(98) "https://www.googleapis.com/plus/v1/activities/z133dxyyhuaqf5tqd04cebxrtuykyfc5vi0/people/resharers" } } ["provider"]=> array(1) { ["title"]=> string(7) "Google+" } ["access"]=> array(3) { ["kind"]=> string(8) "plus#acl" ["description"]=> string(6) "Public" ["items"]=> array(1) { [0]=> array(1) { ["type"]=> string(6) "public" } } } } ["processed":protected]=> array(0) { } } object(Google_Service_Plus_Activity)#269 (28) { ["internal_gapi_mappings":protected]=> array(0) { } ["accessType":protected]=> string(23) "Google_Service_Plus_Acl" ["accessDataType":protected]=> string(0) "" ["actorType":protected]=> string(33) "Google_Service_Plus_ActivityActor" ["actorDataType":protected]=> string(0) "" ["address"]=> NULL ["annotation"]=> NULL ["crosspostSource"]=> NULL ["etag"]=> string(57) ""RqKWnRU4WW46-6W3rWhLR9iFZQM/Z-Jgsn-qD_7-wIVme1yMD5E2Y6k"" ["geocode"]=> NULL ["id"]=> string(33) "z13pt1n4owmog3peg22lzhyirobmu1ivk" ["kind"]=> string(13) "plus#activity" ["locationType":protected]=> string(25) "Google_Service_Plus_Place" ["locationDataType":protected]=> string(0) "" ["objectType":protected]=> string(34) "Google_Service_Plus_ActivityObject" ["objectDataType":protected]=> string(0) "" ["placeId"]=> NULL ["placeName"]=> NULL ["providerType":protected]=> string(36) "Google_Service_Plus_ActivityProvider" ["providerDataType":protected]=> string(0) "" ["published"]=> string(24) "2015-03-20T08:35:56.611Z" ["radius"]=> NULL ["title"]=> string(103) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=1c09b6ce-cedc..." ["updated"]=> string(24) "2015-03-20T08:35:56.611Z" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/Dpn1rWu44Dp" ["verb"]=> string(4) "post" ["modelData":protected]=> array(4) { ["actor"]=> array(4) { ["id"]=> string(21) "104620991895987671420" ["displayName"]=> string(27) "Magazin de scule barbatesti" ["url"]=> string(45) "https://plus.google.com/104620991895987671420" ["image"]=> array(1) { ["url"]=> string(98) "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50" } } ["object"]=> array(6) { ["objectType"]=> string(4) "note" ["content"]=> string(264) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=1c09b6ce-cedc-11e4-8c62-448a5b89d5f1" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/Dpn1rWu44Dp" ["replies"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(88) "https://www.googleapis.com/plus/v1/activities/z13pt1n4owmog3peg22lzhyirobmu1ivk/comments" } ["plusoners"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(96) "https://www.googleapis.com/plus/v1/activities/z13pt1n4owmog3peg22lzhyirobmu1ivk/people/plusoners" } ["resharers"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(96) "https://www.googleapis.com/plus/v1/activities/z13pt1n4owmog3peg22lzhyirobmu1ivk/people/resharers" } } ["provider"]=> array(1) { ["title"]=> string(7) "Google+" } ["access"]=> array(3) { ["kind"]=> string(8) "plus#acl" ["description"]=> string(6) "Public" ["items"]=> array(1) { [0]=> array(1) { ["type"]=> string(6) "public" } } } } ["processed":protected]=> array(0) { } } object(Google_Service_Plus_Activity)#272 (28) { ["internal_gapi_mappings":protected]=> array(0) { } ["accessType":protected]=> string(23) "Google_Service_Plus_Acl" ["accessDataType":protected]=> string(0) "" ["actorType":protected]=> string(33) "Google_Service_Plus_ActivityActor" ["actorDataType":protected]=> string(0) "" ["address"]=> NULL ["annotation"]=> NULL ["crosspostSource"]=> NULL ["etag"]=> string(57) ""RqKWnRU4WW46-6W3rWhLR9iFZQM/YjJYiH1WPwlvGXudZ_Hq21fjRLc"" ["geocode"]=> NULL ["id"]=> string(35) "z13eun0r1tikx3lju04cebxrtuykyfc5vi0" ["kind"]=> string(13) "plus#activity" ["locationType":protected]=> string(25) "Google_Service_Plus_Place" ["locationDataType":protected]=> string(0) "" ["objectType":protected]=> string(34) "Google_Service_Plus_ActivityObject" ["objectDataType":protected]=> string(0) "" ["placeId"]=> NULL ["placeName"]=> NULL ["providerType":protected]=> string(36) "Google_Service_Plus_ActivityProvider" ["providerDataType":protected]=> string(0) "" ["published"]=> string(24) "2015-03-20T08:34:31.517Z" ["radius"]=> NULL ["title"]=> string(103) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=e51795c8-cedb..." ["updated"]=> string(24) "2015-03-20T08:34:31.517Z" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/iubGf6imv4c" ["verb"]=> string(4) "post" ["modelData":protected]=> array(4) { ["actor"]=> array(4) { ["id"]=> string(21) "104620991895987671420" ["displayName"]=> string(27) "Magazin de scule barbatesti" ["url"]=> string(45) "https://plus.google.com/104620991895987671420" ["image"]=> array(1) { ["url"]=> string(98) "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50" } } ["object"]=> array(6) { ["objectType"]=> string(4) "note" ["content"]=> string(264) "http://www.company-civ.localhost.com/provider/endpoint/validation_social/google?validate=e51795c8-cedb-11e4-88a6-448a5b89d5f1" ["url"]=> string(63) "https://plus.google.com/104620991895987671420/posts/iubGf6imv4c" ["replies"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(90) "https://www.googleapis.com/plus/v1/activities/z13eun0r1tikx3lju04cebxrtuykyfc5vi0/comments" } ["plusoners"]=> array(2) { ["totalItems"]=> int(0) ["selfLink"]=> string(98) "https://www.googleapis.com/plus..

{{1}}

3 个答案:

答案 0 :(得分:4)

解决方案是(最终找到):

$service = new \Google_Service_Plus($this->client);
//you can also set range of post (max 100)
$optParams = array('maxResults' => 100);
$activities = $service->activities->listActivities('{PAGE_ID}', 'public',$optParams);

foreach($activities as $activity) {
   $result = $activity->getObject();
}

$result是一个包含公共属性的对象content 所以:

$result->content;

答案 1 :(得分:2)

您可以使用以下网址访问内容:$activity->getObject()->content

答案 2 :(得分:0)

我会在黑暗中拍摄一下。但是你会告诉我这是否有效:

foreach($activities as $activity) {
    $activityInfo = $service->activities->get($activity["id"]);
    var_dump($activityInfo);
}

不确定id是否在数组的这个级别上,因为var_dump不是很整洁。但是示例id是z133dxyyhuaqf5tqd04cebxrtuykyfc5vi0

尝试这种方法并告诉我它是否有效。 (或者至少我们是在正确的方向)

此致