如何从对象,PHP中检索数据

时间:2013-11-13 08:43:12

标签: php

我有一个对象在print_r上输出:

Dropbox\Client Object
(
    [accessToken:Dropbox\Client:private] => secret
    [clientIdentifier:Dropbox\Client:private] => examples-web-file-browser
    [userLocale:Dropbox\Client:private] => 
    [apiHost:Dropbox\Client:private] => api.dropbox.com
    [contentHost:Dropbox\Client:private] => api-content.dropbox.com
    [root:Dropbox\Client:private] => 
    [host] => Dropbox\Host Object
        (
            [api:Dropbox\Host:private] => api.dropbox.com
            [content:Dropbox\Host:private] => api-content.dropbox.com
            [web:Dropbox\Host:private] => www.dropbox.com
        )

)

我如何获得“秘密”的价值?

更新 的var_dump($ dbxClient);

输出:

object(Dropbox\Client)#3 (7) {
  ["accessToken":"Dropbox\Client":private]=>
  string(64) "HrouVh2oRTcAAAAAAAAAARYOdXzK5tA9lCscE24fdnVnt5wYYPSSaK8nITv4PFtc"
  ["clientIdentifier":"Dropbox\Client":private]=>
  string(25) "examples-web-file-browser"
  ["userLocale":"Dropbox\Client":private]=>
  NULL
  ["apiHost":"Dropbox\Client":private]=>
  string(15) "api.dropbox.com"
  ["contentHost":"Dropbox\Client":private]=>
  string(23) "api-content.dropbox.com"
  ["root":"Dropbox\Client":private]=>
  NULL
  ["host"]=>
  object(Dropbox\Host)#2 (3) {
    ["api":"Dropbox\Host":private]=>
    string(15) "api.dropbox.com"
    ["content":"Dropbox\Host":private]=>
    string(23) "api-content.dropbox.com"
    ["web":"Dropbox\Host":private]=>
    string(15) "www.dropbox.com"
  }
}

1 个答案:

答案 0 :(得分:4)

official PHP SDK for Dropboxlib/Dropbox/Client.php行的类文件18中,有一个方法getAccessToken(),它将返回属性accessToken的值。< / p>

所以在你的情况下,这应该做的工作:

var_dump($dbxClient->getAccessToken());

将来,在发布此类问题之前,请先查看SDK和API的文件。