您请求的某些别名不存在:{$ a_data-> id}

时间:2014-11-01 10:56:13

标签: php facebook facebook-graph-api facebook-php-sdk

在我开发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 个答案:

答案 0 :(得分:1)

好像你真的要发送Facebook {$a_data->id}而不是你真正要求的ID - 修改你的代码来发送ID而不是那个字符串

如果将{$....}解释为转义序列,修复此问题就像将单引号更改为双引号一样简单