当我尝试从Twitter API 1.1用户时间线undefined index
screen_name
键值对时,出现以下https://api.twitter.com/1.1/statuses/user_timeline.json
错误
遇到PHP错误
严重性:注意
消息:未定义的索引:screen_name
文件名:controllers / search.php
行号:98
我在print_r()时可以看到screen_name键;存储结果的关联数组:
数组([0] =>数组([created_at] =>星期二三月19 21:55:31 +0000 2013 [id] => 3.141330578148E + 17 [id_str] => 314133057814798336 [text] => 3月26日至31日通过@ 604Now赢取4张每张@VanAutoShow门票 - http://t.co/2G0pyNNgLl RT进入! [来源] => Twitter for Mac [截断] => [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] =>数组([id] => 128700677 [id_str] => 128700677 [name] => Bernard Poon [screen_name] => StackOverflow [location] =>温哥华,BC [描述] =>代码猴 那叫温哥华回家。喜欢Apple产品和新手 摄影师。 [url] => http://t.co/wlxhr5tpes [entities] =>阵列( [url] =>数组([urls] =>数组([0] =>数组([url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [indices] =>数组([0] => 0 1 => 22))))[描述] =>数组([urls] =>数组())) [protected] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => 2010年4月1日星期四23:16:57 +0000 [favourites_count] => 0 [utc_offset] =>
如果我使用Users Show TWitter API 1.1资源而没有错误,我可以访问screen_name键值对。但是,当我使用User Timeline Twitter API 1.1资源时,我收到上述undefined index
错误。下面是我用来访问这两种资源的函数的代码片段:
function does_user_exist($r)
{
// convert to associative array
// inorder to search for keys
$a = json_decode($r, true);
echo "Screen Name: " . $a['screen_name'];
}
非常感谢任何帮助。提前谢谢。
答案 0 :(得分:3)
它在另一个数组中。尝试以下代码
echo "Screen Name: " . $a[0]['screen_name'];