2013-07-24 42 views
0

我可以使用facebook api獲得想要的數據,如興趣,電影等等。使用圖表api從Facebook獲取數據

Array 
(
    [data] => Array 
     (
      [0] => Array 
       (
        [category] => Movie 
        [name] => 3 Idiots Movie 
        [created_time] => 2012-05-11T13:22:34+0000 
        [id] => 441170255909978 
       ) 

      [1] => Array 
       (
        [category] => Movie 
        [name] => Harry Potter 
        [created_time] => 2011-04-11T05:44:14+0000 
        [id] => 156794164312 
       ) 

      [2] => Array 
       (
        [category] => Movie 
        [name] => Official Narnia: Voyage of the Dawn Treader 
        [created_time] => 2011-03-10T18:26:57+0000 
        [id] => 190647217857 
       ) 

      [3] => Array 
       (
        [category] => Movie general 
        [name] => Harry Porter 
        [created_time] => 2011-03-10T18:26:57+0000 
        [id] => 360697777345 
       ) 

我怎樣才能得到細節,只給出電影和ID,以便我可以存儲在數據庫中?

回答

1

你可以做以下形式的東西:

foreach (Array['data'] as $var) 
{ 
    $ID=$var['id']; 
    $Name=$var['name']; 
} 

注:Array['data'],陣列將是你在保存這些數據的變量名

+0

謝謝你,我的打印數據的代碼是'$ user_interest = $ facebook-> api('/ me/movies'); print_r($ user_interest);'我應該把user_interest當作Array []? – user123

+0

'foreach($ user_interest as $ var) \t { \t $ ID = $ var ['id']; \t $ Name = $ var ['name']; \t print_r($ Name); \t}'給出錯誤'注意事項:未定義指數:ID在/opt/lampp/htdocs/FB/facebook-php-sdk/examples/process_facebook.php在線26 注意:未定義指數:名稱在/ opt第27行的/lampp/htdocs/FB/facebook-php-sdk/examples/process_facebook.php ' – user123

+1

我認爲它應該是foreach($ user_interest [0]作爲$ var),請嘗試這種方式,因爲它是一個數組本身有一個名爲Data的元素。 – Nareg

相關問題