【发布时间】:2014-01-15 09:53:37
【问题描述】:
当我请求 API 值时,$results 返回一个数组,但 google 在他们的示例中使用 $results 作为对象?
我总是得到一个
致命错误:在非对象上调用成员函数 getKind()
他们是否更改了库并且他们自己的示例不再工作,或者我这边有什么错误?但到目前为止我还没有更改代码,除非 $ optparams 值。
PS:到目前为止一切正常,只是对象/数组问题。
我得到每个print_r($results):
Array (
[kind] => analytics#realtimeData
[id] => https://www.googleapis.com/analytics/v3/data/realtime?ids=ga:**censored**&dimensions=ga:medium&metrics=ga:activeVisitors
[query] => Array (
[ids] => ga:**censored**
[dimensions] => ga:medium
[metrics] => Array (
[0] => ga:activeVisitors
)
[max-results] => 1000
)
[totalResults] => 8
[selfLink] => https://www.googleapis.com/analytics/v3/data/realtime?ids=ga:**censored**&dimensions=ga:medium&metrics=ga:activeVisitors
[profileInfo] => Array (
[profileId] => **censored**
[accountId] => **censored**
[webPropertyId] => **censored**
[internalWebPropertyId] => **censored**
[profileName] => **censored**
[tableId] => realtime:**censored**
)
[columnHeaders] => Array (
[0] => Array (
[name] => rt:medium
[columnType] => DIMENSION
[dataType] => STRING
)
[1] => Array (
[name] => ga:activeVisitors
[columnType] => METRIC
[dataType] => INTEGER
)
)
[totalsForAllResults] => Array (
[ga:activeVisitors] => 752
)
[rows] => Array (
[0] => Array (
[0] => DIRECT [1] => 283
)
[1] => Array (
[0] => E-Mail [1] => 5
)
[2] => Array (
[0] => ORGANIC [1] => 287
)
[3] => Array (
[0] => REFERRAL [1] => 92
)
[4] => Array (
[0] => SOCIAL [1] => 49
)
[5] => Array (
[0] => cpc [1] => 23
)
[6] => Array (
[0] => e-mail [1] => 8
)
[7] => Array (
[0] => facebook [1] => 5
)
)
)
【问题讨论】:
-
“在非对象上”表示您尝试访问的对象是
NULL。您确定要取回数据吗? -
代码在可用的 url 下(不想炸毁网站),它是一样的.. 是的,如果我使用 print_r($results) 我得到实时值..
-
那么,
print_r显示了什么?也许您只是访问错误? -
我用 print_r 结果编辑了帖子。我不确定,并没有真正改变访问周围的任何东西。直到以下部分 $analytics 仍然是一个对象并且 $results 也应该成为一个对象?:尝试 { $results = $analytics->data_realtime->get('ga:xxxxx', 'ga:activeVisitors', $optParams);在每个步骤中使用 gettype() 对其进行多次检查..
标签: php api google-analytics google-analytics-api