How to access object data and display the comments - php

How do I access the comments and display them?
stdClass Object
(
[stream] => stdClass Object
(
[id] => 521734635_403433313001586
[from] => stdClass Object
(
[name] => Jonathan Rosario
[id] => 521734635
)
[message] => What if we do the same action in our country?...i just hope they be fair. Its just unfair that they also ban our Bibles while we never ban their Qu'rans in our country.
[comments] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[id] => 521734635_403433313001586_90696065
[from] => stdClass Object
(
[name] => ''
[id] => 570761262
)
[message] => test
[created_time] => 2012-03-29T10:01:49+0000
)
[1] => stdClass Object
(
[id] => 521734635_403433313001586_90696070
[from] => stdClass Object
(
[name] => Alwaynne Kevin
[id] => 100000364267158
)
[message] => Oo nga...bakit ganyan sila...hahah.!
[created_time] => 2012-03-29T10:07:52+0000
)
[2] => stdClass Object
(
[id] => 521734635_403433313001586_90696146
[from] => stdClass Object
(
[name] => Jp Peña
[id] => 100000599584313
)
[message] => they're just doing what the "christian" crusaders did to them.
[created_time] => 2012-03-29T10:33:12+0000
)
)
[count] => 3
)
[picture] => http://external.ak.fbcdn.net/safe_image.php?d=AQCr7a57qDUU2MHR&w=90&h=90&url=http%3A%2F%2Fwww.interaksyon.com%2Fassets%2Fimages%2Farticles%2Finterphoto_1332546902.jpg
[name] => Top Saudi cleric 'issues fatwa' on Christian churches; Bishops alarmed - InterAksyon.com
[description] => Christian bishops are sharply criticizing Saudi Arabia's top religious official after reports that he issued a fatwa saying all churches on the Arabian Peninsula should be destroyed. At least 3.5 million Christians live in the Gulf Arab region. They are mostly Catholic workers from the Philippines a...
[created_time] => 2012-03-29T10:00:41+0000
)
)

you got the whole list of objects in comments so give try following:
foreach( $yourObj->stream->comments as $comment){
echo sprintf('%s: %s', $comment->from->name, $comment->message);
}

Related

how to retrieve variable from object

I want to retrieve $se_module value from my object. How can I get that? I can easily get others by $object->Owner->name. I've tried $object->{$se_module}, but got error as undefined variable.
stdClass Object
(
[Owner] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[Modified_Time] => 2019-01-09T21:25:05-05:00
[$attachments] =>
[Created_Time] => 2019-01-09T21:25:05-05:00
[Parent_Id] => stdClass Object
(
[name] =>
[id] => 2880896000011553097
)
[$editable] => 1
[$se_module] => Deals
[Modified_By] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[$size] =>
[$voice_note] =>
[id] => 2880896000011676081
[Created_By] => stdClass Object
(
[name] => Merv Henry
[id] => 2880896000003943001
)
[Note_Title] =>
[Note_Content] => This unit needs 1# DA97-12540K & 1# DA97-13718C
Quote is needed
)
you cane make it as array then you can get it
$data = (array)$se_module;
then can get data like this
$data['Modified_Time'];

StdClass Object to String , Iterating through the array

Hi I've asked this before but didn't get a correct answer. I am trying to get the Tracks to print from the stdObject. I've tried many possible answers but nothing worked apart from using:
var_dump("Track Title: " .
$response->Items->Item->Tracks->Disc->Track[0]->_);
But this only works if you know how many tracks there are for certain CD, I am calling 500 ASIN's at once. So basically I would like to parse the Tracks array into a String
[Items] => stdClass Object
(
[Request] => stdClass Object
(
[IsValid] => True
[ItemLookupRequest] => stdClass Object
(
[IdType] => ASIN
[ItemId] => B000002OGL
[ResponseGroup] => Tracks
[VariationPage] => All
)
)
[Item] => stdClass Object
(
[ASIN] => B000002OGL
[Tracks] => stdClass Object
(
[Disc] => stdClass Object
(
[Track] => Array
(
[0] => stdClass Object
(
[_] => Mustang Sally
[Number] => 1
)
[1] => stdClass Object
(
[_] => Take Me To The River
[Number] => 2
)
[2] => stdClass Object
(
[_] => Chain Of Fools
[Number] => 3
)
[3] => stdClass Object
(
[_] => The Dark End Of The Street
[Number] => 4
)
[4] => stdClass Object
(
[_] => Destination: Anywhere
[Number] => 5
)
[5] => stdClass Object
(
[_] => I Can't Stand The Rain
[Number] => 6
)
[6] => stdClass Object
(
[_] => Try A Little Tenderness
[Number] => 7
)
[7] => stdClass Object
(
[_] => Treat Me Right
[Number] => 8
)
[8] => stdClass Object
(
[_] => Do Right Woman Do Right Man
[Number] => 9
)
[9] => stdClass Object
(
[_] => Mr. Pitiful
[Number] => 10
)
[10] => stdClass Object
(
[_] => I Never Loved A Man
[Number] => 11
)
[11] => stdClass Object
(
[_] => In The Midnight Hour
[Number] => 12
)
[12] => stdClass Object
(
[_] => Bye Bye Baby
[Number] => 13
)
[13] => stdClass Object
(
[_] => Slip Away
[Number] => 14
)
)
[Number] => 1
)
)
)
)
)
you can do
foreach($response->Items->Item->Tracks->Disc->Track as $track){
echo "Track Title: ". $track->_;// or track title
}

How to loop through a LinkedIn API response?

I am retrieving connections via LinkedIn's API.
This is a sample of the response. All I want to do is loop through this using PHP, accessing first and last names. Should be simple, but I am stumped. Thanks.
stdClass Object ( [_total] => 420 [values] => Array ( [0] => stdClass
Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] =>
stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass
Object ( [name] => x-li-auth-token [value] => name:AnUY ) ) ) [url] =>
http://api.linkedin.com/v1/people/7yw8k_sjqf ) [firstName] => John
[headline] => Finance Manager at ABC. [id] => 7yw8k_sjqf [industry] =>
Insurance [lastName] => Doe [location] => stdClass Object ( [country]
=> stdClass Object ( [code] => us ) [name] => Greater Atlanta Area ) [pictureUrl] =>
http://m.c.lnkd.licdn.com/mpr/mprx/0_73E_PMM3nzAIZLG03bHpPRo3qvCwZL_0DhYpPRogIxiFs7jUYPVRGNRGC1mGegyyqdihoC
[siteStandardProfileRequest] => stdClass Object ( [url] =>
http://www.linkedin.com/profile/view?id=2633833&authType=name&authToken=AnUY&trk=api*a189561*s197687*
) ) [1] => stdClass Object ( [apiStandardProfileRequest] => stdClass
Object ( [headers] => stdClass Object ( [_total] => 1 [values] =>
Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] =>
name:tpAo ) ) ) [url] => http://api.linkedin.com/v1/people/FW8obZbI8R
) [firstName] => Jeremy [headline] => Owner, BCD [id] => FW8obZbI8R
[industry] => Computer Software [lastName] => Doe [location] =>
stdClass Object ( [country] => stdClass Object ( [code] => us ) [name]
=> Greater Chicago Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_Lw2NlImcd1e6LmQpL2mIleOMIcf9LeFpbu4IlexHq-R6V2ryWSpZ0HI6LM7rXeaEYf3Gt69H
[siteStandardProfileRequest] => stdClass Object ( [url] =>
http://www.linkedin.com/profile/view?id=6700159&authType=name&authToken=tpAo&trk=api*a189561*s197687*
) ) [2] => stdClass Object ( [apiStandardProfileRequest] => stdClass
Object ( [headers] => stdClass Object ( [_total] => 1 [values] =>
Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] =>
name:eETp ) ) ) [url] => http://api.linkedin.com/v1/people/a7-dvlvc7K
) [firstName] => Jane [headline] => Sr. Consultant System Integration
at AT&T [id] => a7-dvlvc7K [industry] => Telecommunications [lastName]
=> Doe [location] => stdClass Object ( [country] => stdClass Object ( [code] => us ) [name] => Greater New York City Area ) [pictureUrl] =>
http://m.c.lnkd.licdn.com/mpr/mprx/0_459zxGU8TBpTZjvisicExTgSSvZCsYXisCGExTR-t1ut5V1_N_6JA37p_Z4gJQqIK653RvmW
[siteStandardProfileRequest] => stdClass Object ( [url] =>
http://www.linkedin.com/profile/view?id=119413921&authType=name&authToken=eETp&trk=api*a189561*s197687*
) ) [3] => stdClass Object ( [apiStandardProfileRequest] => stdClass
Object ( [headers] => stdClass Object ( [_total] => 1 [values] =>
Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] =>
name:HjUG ) ) ) [url] => http://api.linkedin.com/v1/people/aie8Zpk9Gm
) [firstName] => John [headline] => Financial Information/Market Data
Professional [id] => aie8Zpk9Gm [industry] => Financial Services
[lastName] => Smith [location] => stdClass Object ( [country] =>
stdClass Object ( [code] => gb ) [name] => Glasgow, United Kingdom )
[pictureUrl] =>
http://m.c.lnkd.licdn.com/mpr/mprx/0_N0TLAL3BTlHZCVAbTNTAD03RCjngvsAbCIY-JfOxvg4JldxF9L7MShCp_Avp_ROhKS8LNY
[siteStandardProfileRequest] => stdClass Object ( [url] =>
http://www.linkedin.com/profile/view?id=1562499&authType=name&authToken=HjUG&trk=api*a189561*s197687*
) ) [4] => stdClass Object ( [apiStandardProfileRequest] => stdClass
Object ( [headers] => stdClass Object ( [_total] => 1 [values] =>
Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] =>
name:aZIS ) ) ) [url] => http://api.linkedin.com/v1/people/XTGgSuagWI
) [firstName] => Bob [headline] => CEO, Nycomed US at NMO [id] =>
XTGgSuagWI [industry] => Pharmaceuticals [lastName] => brown
[location] => stdClass Object ( [country] => stdClass Object ( [code]
=> us ) [name] => Greater New York City Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_UciCehxmKngbM15je_qytdVG-zSbJrcje_92S7a-DlsFcA1m6iCGyXsjl-uwsq3ybXXbrd1L
[siteStandardProfileRequest] => stdClass Object ( [url] =>
What you have as the response is an stdclass which will have all of its properties public.
This is how you iterate it:
$response = $this->getResponseFromLinkedIn();
foreach ($response->values as $value) {
$firstName = $value->firstName;
$lastName = $value->lastName;
// do something with the extracted values!
}

PHP Facebook API - Access Object Array Item

I have an object array (shown at the bottom) and can access the data by doing this:
echo $MyVariable->id;
echo $MyVariable->type;
and so on. However, I can't access the item [count] by doing this:
echo $MyVariable->id;
Anybody know why? Count seems to be used for something else, a count perhaps?
stdClass Object (
[id] => 573948779291487
[from] => stdClass Object (
[category] => Bar
[category_list] => Array (
[0] => stdClass Object (
[id] => 218693881483234
[name] => Pub
)
[1] => stdClass Object (
[id] => 164049010316507
[name] => Gastropub
) )
[name] => The Melbourne Arms
[id] => 533195070033525
)
[name] => The Melbourne Arms Gallery
[location] => The Melbourne Arms
[place] => stdClass Object (
[id] => 533195070033525
[name] => The Melbourne Arms
[location] => stdClass Object (
[street] => Main Street
[city] => Melbourne
[country] => United Kingdom
[zip] => YO42 4QJ
[latitude] => 53.8872441
[longitude] => -0.8554097
) )
[link] => http://www.facebook.com/album.php?fbid=573948779291487&id=533195070033525&aid=1073741825
[cover_photo] => 573948812624817
[count] => 28
[type] => normal
[created_time] => 2013-03-13T22:22:45+0000
[updated_time] => 2013-03-13T22:34:40+0000
[can_upload] =>
[likes] => stdClass Object (
[data] => Array (
[0] => stdClass Object (
[id] => 1361671776
[name] => Lesley Maiden
)
[1] => stdClass Object (
[id] => 518580863
[name] => Diane Maiden
)
[2] => stdClass Object (
[id] => 1254875611
[name] => Vanessa Wilson
)
[3] => stdClass Object (
[id] => 533195070033525
[name] => The Melbourne Arms
)
[4] => stdClass Object (
[id] => 100001664649752
[name] => Bowen Lee
) )
[paging] => stdClass Object (
[next] => https://graph.facebook.com/573948779291487/likes?limit=25&offset=25&__after_id=100001664649752
) ) ) 1
Try handling your data differently
$data = file_get_contents("https://graph.facebook.com/573948779291487");
$data = json_decode($data, true);
echo $data['count'];

Freshbooks API show details

I am using the php library from here and I have a small problem.
To get some info for a invoice 118868, I can do this
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print_r($invoice);
?>
This is the output for print_r
Class Object ( [#attributes] => stdClass Object ( [status] => ok ) [invoice] => stdClass Object ( [invoice_id] => 00000219023 [estimate_id] => stdClass Object ( ) [number] => 8822 [client_id] => 83 [contacts] => stdClass Object ( [contact] => stdClass Object ( [contact_id] => 0 ) ) [recurring_id] => stdClass Object ( ) [organization] => Jimmy Thwart [first_name] => stdClass Object ( ) [last_name] => stdClass Object ( ) [p_street1] => stdClass Object ( ) [p_street2] => stdClass Object ( ) [p_city] => stdClass Object ( ) [p_state] => stdClass Object ( ) [p_country] => stdClass Object ( ) [p_code] => stdClass Object ( ) [po_number] => 10002 [status] => sent [amount] => 16.90 [amount_outstanding] => 16.90 [paid] => 0.00 [date] => 2013-01-31 00:00:00 [notes] => stdClass Object ( ) [terms] => Your slot can only be secured upon payment. Any reservation made before payment will only be guaranteed for 2 days. [discount] => 0 [url] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [auth_url] => https://example.freshbooks.com/invoices/219023 [links] => stdClass Object ( [client_view] => https://example.freshbooks.com/view/vgPb2TNGCR7n8JV [view] => https://example.freshbooks.com/invoices/219023 [edit] => https://example.freshbooks.com/invoices/219023/edit ) [return_uri] => stdClass Object ( ) [updated] => 2013-01-31 02:25:13 [currency_code] => SGD [language] => en [vat_name] => stdClass Object ( ) [vat_number] => stdClass Object ( ) [folder] => active [staff_id] => 1 [lines] => stdClass Object ( [line] => stdClass Object ( [line_id] => 1 [name] => Lady 1pax [description] => Services (1 pax) [unit_cost] => 16.90 [quantity] => 1 [amount] => 16.90 [tax1_name] => stdClass Object ( ) [tax2_name] => stdClass Object ( ) [tax1_percent] => 0 [tax2_percent] => 0 [compound_tax] => 0 [type] => Item ) ) [gateways] => stdClass Object ( [gateway] => stdClass Object ( [name] => PayPal ) ) ) )
I hope the output can only be the URL and not this whole chunk of code.
Output wanted:
https://example.freshbooks.com/view/vgPb2TNGCR7n8JV
However, it lists all information of the invoice. How do I get only the invoice URL?
Well, using the output of your code, you can see what the elements of $invoice are. Use the one that you need.
Invoice is an instane of a class. You should treat it like all instances.
To get URL value you can do the next:
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->url;
?>
or there's another possible value you're looking for:
<?php
$invoice_id=118868;
$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->links->client_view;
?>
According to official API doc <url> is not supporting any more, so you should use <links> "element to provide your customers with direct links to the invoice for editing, viewing by the client and viewing by an administrator."

Categories