简体   繁体   English

无法访问键值对Twitter API用户时间轴

[英]Unable to Access Key-Value Pair Twitter API User Timeline

I am getting the following undefined index error when I try to access the screen_name key value pair from Twitter API 1.1 User Timeline https://api.twitter.com/1.1/statuses/user_timeline.json 当我尝试从Twitter API 1.1用户时间轴https://api.twitter.com/1.1/statuses/user_timeline.json访问screen_name键值对时,出现以下undefined index错误。

A PHP Error was encountered 遇到PHP错误

Severity: Notice 严重程度:注意

Message: Undefined index: screen_name 消息:未定义的索引:screen_name

Filename: controllers/search.php 文件名:controllers / search.php

Line Number: 98 行号:98

I can see the screen_name key when I print_r(); 当我print_r()时,我可以看到screen_name键; the associative array that stores the results: 存储结果的关联数组:

Array ( [0] => Array ( [created_at] => Tue Mar 19 21:55:31 +0000 2013 [id] => 3.141330578148E+17 [id_str] => 314133057814798336 [text] => Win a 4-Pack of tickets to the @VanAutoShow March 26-31 via @604Now – http://t.co/2G0pyNNgLl RT to Enter! [source] => Twitter for Mac [truncated] => [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] => Array ( [id] => 128700677 [id_str] => 128700677 [name] => Bernard Poon [screen_name] => StackOverflow [location] => Vancouver, BC [description] => Code Monkey that calls Vancouver home. Loves Apple products and newbie photographer. [url] => http://t.co/wlxhr5tpes [entities] => Array ( [url] => Array ( [urls] => Array ( [0] => Array ( [url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [indices] => Array ( [0] => 0 1 => 22 ) ) ) ) [description] => Array ( [urls] => Array ( ) ) ) [protected] Array([0] => Array([created_at] => Tue Mar 19 21:55:31 +0000 2013 [id] => 3.141330578148E + 17 [id_str] => 314133057814798336 [text] =>赢得一个4件装@VanAutoShow 3月26日至31日通过@ 604Now的门票–通过http://t.co/2G0pyNNgLl RT进入![源] => Mac的Twitter [截断] => [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 [位置] =>不列颠哥伦比亚省温哥华[说明] =>叫温哥华的代码猴子,喜欢苹果产品和新手摄影师。[URL] => http://t.co/wlxhr5tpes [实体] =>数组([url] => Array([urls] => Array([0] => Array([url] => http://t.co/wlxhr5tpes [expanded_url] => http://ceciliaandbernard.com [display_url] => ceciliaandbernard.com [索引] =>数组([0] => 0 1 => 22)))))[描述] =>数组([urls] =>数组())))[受保护] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => Thu Apr 01 23:16:57 +0000 2010 [favourites_count] => 0 [utc_offset] => => [关注者人数] => 157 [朋友人数] => 13 [列出的人数] => 4 [创建的人数] => 2010年4月1日星期四23:16:57 +0000 [收藏夹人数] => 0 [utc_offset] =>

I am able to access the screen_name key value pair if I use the Users Show TWitter API 1.1 resource with no errors. 如果我使用没有错误的Users Show TWitter API 1.1资源,则可以访问screen_name键值对。 However, when I use the User Timeline Twitter API 1.1 resource, I get the above undefined index error. 但是,当我使用用户时间轴 Twitter API 1.1资源时,出现上述undefined index错误。 Below is a code snippet of the function I'm using to access both of these resources with different results: 下面是我用来访问这两种资源并获得不同结果的函数的代码片段:

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'];       
}

Any assistance will be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

its inside another array. 它在另一个数组中。 try the following code 试试下面的代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM