How to print nested stdclass object array - php

I am trying to print values in this nested stdClass Object but I'm having trouble accessing them. How do I print the ID?
stdClass Object (
[AddUserWithLimitResult] => stdClass Object (
[Header] => stdClass Object (
[Code] => UserAdded
[Description] => User created
)
[ID] => 2243272
[UserName] => gmail.com
[FirstName] => sar
[LastName] => Sea
[Email] => gmail.com
[SubDomain] => olo
)
)
I tried this:
$object->AddUserWithLimitResult->Header->Code->ID;

If you tab out the output it becomes clear that ID is a property of AddUserWithLimitResult
stdClass Object (
[AddUserWithLimitResult] => stdClass Object (
[Header] => stdClass Object (
[Code] => UserAdded
[Description] => User created
)
[ID] => 2243272
[UserName] => gmail.com
[FirstName] => sar
[LastName] => Sea
[Email] => gmail.com
[SubDomain] => olo
)
)
$object->AddUserWithLimitResult->ID
Edit: It looks like you updated the question with the tabbed code. When I saw it it was difficult to tell which properties belonged to which objects.

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'];

Typeform api, change variables names in results

I am using typeform as a tool to get feedback and contact infos.
By using the api, I get results from my survey with the following format :
[answers] => Array
(
[0] => stdClass Object
(
[field] => stdClass Object
(
[id] => XdLvktpeAVmc
[type] => short_text
[ref] => 88e1657e-516b-4219-8086-52ba80e55eb0
)
[type] => text
[text] => Test1
)
[1] => stdClass Object
(
[field] => stdClass Object
(
[id] => QLYWXINAKoeS
[type] => number
[ref] => c431bf84-7305-4171-a659-67191b797651
)
[type] => number
[number] => 111111111
)
[2] => stdClass Object
(
[field] => stdClass Object
(
[id] => wRSL0qJ7BSWH
[type] => email
[ref] => 719312ce-9ae9-4a45-9b9f-fdfaf3d23dc1
)
[type] => email
[email] => Test1#email.com
)
)
[hidden] => stdClass Object
(
)
[calculated] => stdClass Object
(
[score] => 0
)
)
Is it possible to change the name of the variables (text, number, email) ? I've tried using hidden fields but it's not the feature to use.
Thanks

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."

How to access object data and display the comments

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

Post a comment and like a news on a facebook fan page outside facebook

I retrieved my wall feed with php (without the sdk) and i got this below. Can i like the news and comment it via my website and not via facebook ?
does the comment ant the like can be differents ?
[0] => stdClass Object
(
[name] => Comment
[link] => http://www.facebook.com/143788389048247/posts/143799919047094
)
[1] => stdClass Object
(
[name] => Like
[link] => http://www.facebook.com/143788389048247/posts/143799919047094
)
stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[id] => 143788389048247_143799919047094
[from] => stdClass Object
(
[name] => Dirtier than.
[category] => Cause
[id] => 143788389048247
)
[message] => The first quote of this page
"Dirtier than Ron Jeremy's Browser History"
[actions] => Array
(
[0] => stdClass Object
(
[name] => Comment
[link] => http://www.facebook.com/143788389048247/posts/143799919047094
)
[1] => stdClass Object
(
[name] => Like
[link] => http://www.facebook.com/143788389048247/posts/143799919047094
)
)
[privacy] => stdClass Object
(
[description] => Public
[value] => EVERYONE
)
[type] => status
[created_time] => 2011-09-02T16:33:01+0000
[updated_time] => 2011-09-02T16:33:01+0000
[comments] => stdClass Object
(
[count] => 0
)
[is_published] => 1
)
yes you can you just need to post a like or comment to facebook
check this link:
https://developers.facebook.com/docs/reference/api/post/

Categories