Freshbooks API显示详细信息

时间:2013-01-31 06:53:43

标签: php freshbooks-api

我正在使用这里的php库,我遇到了一个小问题。

要获取发票118868的一些信息,我可以这样做

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print_r($invoice);
?>

这是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 ) ) ) ) 

我希望输出只能是URL而不是整个代码块。 需要输出:

https://example.freshbooks.com/view/vgPb2TNGCR7n8JV

但是,它列出了发票的所有信息。如何仅获取发票URL?

2 个答案:

答案 0 :(得分:0)

好吧,使用代码的输出,您可以看到$invoice的元素是什么。使用你需要的那个。

答案 1 :(得分:0)

发票是班级的一个实例。你应该像对待所有实例一样对待它。

要获取URL值,您可以执行下一步:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->url;
?>

或者您正在寻找另一种可能的价值:

<?php
$invoice_id=118868;

$invoice=$freshbooks->invoiceGet($invoice_id);
print $invoice->links->client_view;
?>

根据official API doc <url>不再支持,因此您应使用<links>“元素为您的客户提供发票的直接链接,以便进行编辑,客户查看和由管理员查看。“