2014-11-01 45 views
-1

在我開發Facebook應用程序時,出現以下錯誤,我無法更正: 您請求的某些別名不會存在:{$ a_data-> ID}

這裏是我的代碼:

$request = new FacebookRequest($session, 'GET', '/me/albums?access_token='.$accessToken.'&limit=500'); 
     $response = $request->execute(); 
     $getUserAlbums = $response->getGraphObject(); 

     $userAlbums = $getUserAlbums->asArray(); 

     # logic for finding most liked user album 
     foreach($userAlbums['data'] as $a_data){ 
      var_dump($a_data); 
      $request = new FacebookRequest($session, 'GET', '/{$a_data->id}/likes?access_token='.$accessToken.'&limit=500'); 
      $response = $request->execute(); 
      $getAlbumLikes = $response->getGraphObject(); 

      $a_likes = $getAlbumLikes->asArray(); 
       foreach($a_likes['data'] as $a_likes1){ 
        $a_like_array[] = $a_likes1->name; 
        $request = new FacebookRequest($session, 'GET', '{/$a_likes1->id}?access_token='.$accessToken.'&limit=500'); 
        $response = $request->execute(); 
        $getUserLikes = $response->getGraphObject(); 
        $demouser_profile1 = $getUserAlbums->asArray(); 

        if($demouser_profile1->gender == "male") 
         $mtalbum++; 
        else 
         $ftalbum++; 
       } 

       $a_no_of_likes = count($a_like_array); 
       echo "<br>".$a_no_of_likes; 

       if($highest_alikes < $a_no_of_likes){ 
        $highest_alikes = $a_no_of_likes; 
        $req_album = $a_data; 
        $album_like_array = $a_like_array; 
        $malbum = $mtalbum; 
        $falbum = $ftalbum; 
       } 
       $a_like_array = array();  
       $mtalbum = $ftalbum = 0; 
      } 

,這裏是在PHP中使用的var_dump調試時我收到JSON。

object(stdClass)#14 (11){ 
    [ 
     "id" 
    ] => string(15) "340014122769940" [ 
     "from" 
    ] => object(stdClass)#15 (2) { 
     [ 
     "id" 
     ]  => string(15) "100002840667886"  [ 
     "name" 
     ]  => string(14) "Himanshu Gupta" 
    } [ 
     "name" 
    ] => string(12) "Cover Photos" [ 
     "link" 
    ] => string(84) "https://www.facebook.com/album.php?fbid=340014122769940&id=100002840667886&aid=66194" [ 
     "cover_photo" 
    ] => string(15) "340014129436606" [ 
     "privacy" 
    ] => string(8) "everyone" [ 
     "count" 
    ] => int(2) [ 
     "type" 
    ] => string(5) "cover" [ 
     "created_time" 
    ] => string(24) "2013-02-17T09:20:54+0000 " [" updated_time" 
]=> string(24) "2013-11-03T06:40:57+0000" ["can_upload" 
]=> bool(false) 
} 

如何糾正?

+1

您需要先了解PHP如何首先運行... http://php.net/manual/en/language.types.string.php#language .types.string.parsing – CBroe 2014-11-02 15:55:54

回答

1

好像你從字面上發送的,而不是你其實是要索要ID Facebook的{$a_data->id} - 修復你的代碼發送ID,而不是該字符串的

如果{$....}被解釋爲轉義序列,固定這可以像將單引號更改爲雙引號一樣簡單

+1

@lgy非常感謝,現在就工作!我試圖從一兩天內解決這個錯誤,但僅僅通過將單引號改爲雙引號即可解決問題。再次感謝。 – 2014-11-03 10:20:44

相關問題