Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all activities from a Google+ page and access the content

I`m trying to obtain all activities from a G+ page using Google PHP Api Client:

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

The result is an array of Google_Service_Plus_Activity objects. The problem is that I want to access the content of one of the activities to search for a string, but this is under ["modelData":protected]=> array(1) as ["content"]=> string(int) "my_string". Is there a possibility to access the content?

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..
like image 792
Gligor Florin Avatar asked Mar 20 '15 09:03

Gligor Florin


2 Answers

The solution is (found it finally):

$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();
}

The $result is an Object which contains a public property, content So:

$result->content;
like image 90
Gligor Florin Avatar answered Oct 20 '22 00:10

Gligor Florin


You can access the content by using: $activity->getObject()->content

like image 40
Beniamin Szabo Avatar answered Oct 20 '22 00:10

Beniamin Szabo