dongliao1860 2013-08-06 15:04
浏览 23
已采纳

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

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

A PHP Error was encountered

Severity: Notice

Message: Undefined index: screen_name

Filename: controllers/search.php

Line Number: 98

I can see the screen_name key when I print_r(); 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] => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => Thu Apr 01 23:16:57 +0000 2010 [favourites_count] => 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. However, when I use the User Timeline Twitter API 1.1 resource, I get the above undefined index error. 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.

  • 写回答

1条回答 默认 最新

  • douhu7807 2013-08-06 15:06
    关注

    its inside another array. try the following code

    echo "Screen Name: " . $a[0]['screen_name'];       
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么