2013-08-06 18 views
0

我正在以下undefined index錯誤,當我嘗試訪問Twitter的API 1.1用戶時間軸screen_name鍵值對https://api.twitter.com/1.1/statuses/user_timeline.json無法訪問鍵值對Twitter的API用戶時間軸

遇到

一個PHP錯誤

嚴重性:注意

消息:未定義指數:SCREEN_NAME

文件名:控制器/ search.ph p

行號:98

我可以看到SCREEN_NAME鍵時我的print_r();關聯數組存儲的結果:

陣列([0] =>數組([created_at] =>星期二03月19日21時55分31秒0000 2013 [ID] => 3.141330578148E + 17 [通過@ 604Now贏得4VGA門票到@VanAutoShow 3月26日到31日 - http://t.co/2G0pyNNgLl RT到Enter![源代碼] =>適用於Mac的Twitter [truncated] => 314133057814798336 [text] => [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 [l ] =>溫哥華,不列顛哥倫比亞省[說明] =>代碼猴 ,稱爲溫哥華的家。愛蘋果產品和新手 攝影師。數組( http://t.co/wlxhr5tpes [expanded_url] =>http://ceciliaandbernard.com [] =>陣列([url] => Array([0] => Array [[entities] => (array)()) [保護]數組([數組])[數組([0] => 0) => [followers_count] => 157 [friends_count] => 13 [listed_count] => 4 [created_at] => Thu Apr 01 23:16:57 +0000 2010 [favourites_count] => 0 [utc_offset] =>

我能夠訪問screen_name鍵值對,如果我使用Users Show TWitter API 1.1資源沒有錯誤。但是,當我使用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'];  
} 

任何幫助將不勝感激。提前致謝。

回答

3

其內部另一個陣列。請嘗試以下代碼

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

+1感謝您的回覆。我這麼認爲,但我仍然得到這個'未定義的索引'錯誤後,將其更改爲$ a [0] ['screen_name'];'。我使用的屏幕名稱是正確的。不知道爲什麼我仍然得到這個錯誤 – Anthony

+0

非常感謝指出我在正確的方向。這工作! '回聲「屏幕名稱:」。 $ A [0] [ '用戶'] [ 'SCREEN_NAME'];' – Anthony