无法访问键-值对Twitter API用户日程表


Unable to Access Key-Value Pair Twitter API User Timeline

当我尝试从Twitter API 1.1用户时间轴https://api.twitter.com/1.1/statuses/user_timeline.json 访问screen_name键值对时,出现以下undefined index错误

遇到PHP错误

严重性:通知

消息:未定义的索引:screen_name

文件名:controllers/search.php

线路编号:98

当我打印_r()时,我可以看到screen_name键;存储结果的关联数组:

Array([0]=>Array([created_at]=>2013年3月19日星期二21:55:31+0000[id]=>3.141330578148E+17[id_str]=>314133057814798336[text]=>通过@604Now赢得3月26日至31日@VanAutoShow的4包门票-http://t.co/2G0pyNNgLlRT进入![来源]=>Mac版Twitter[截断]=>[in_reply_to_status_id]=>[in_reply_to-status_id_str]=>[in_reply_to_user_id]=>[in_ply_to_uuser_id_str]=>[im_reply_to_screen_name]=>[user]=>阵列([id]=>128700677[id_str]=>128700677[名称]=>Bernard Poon[屏幕名称]=>StackOverflow[位置]=>不列颠哥伦比亚省温哥华[描述]=>Code Monkey把温哥华称为家。喜爱苹果产品和新手拍照者[url]=>http://t.co/wlxhr5tpes[entitys]=>阵列([url]=>数组([urls]=>数组)[0]=>数组([url]=>http://t.co/wlxhr5tpes[expanded_url]=>http://ceciliaandbernard.com[display_url]=>ceciliaandbernard.com[index]=>数组([0]=>01=>22)))[描述]=>数组([urls]=>数组())[protected]=>[followers_count]=>157[friends_count]=>13[listed_count]=>4[created_at]=>2010年4月1日星期四23:16:57+000[profiletes_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'];       
}

如有任何协助,我们将不胜感激。提前谢谢。

它在另一个数组中。尝试以下代码

echo "Screen Name: " . $a[0]['screen_name'];