I have the following PHP code:
define('TOKEN_FILE', 'fb_page_accestoken.txt'); // dont need to change this
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
));
$access_token = file_get_contents('fb_app_token.txt');
$response = "https://graph.facebook.com/me/accounts?access_token=".$access_token;
$responsez = json_decode(file_get_contents($response ,true));
print_r($responsez);
When I use the above code I decode the JSON string and get the following:
stdClass Object ( [data] => Array ( [0] => stdClass Object ( [category] => Media/news/publishing [name] => PAGE ABC [access_token] => abcdefghijklmnopqrstuvwxyz1234567890 [perms] => Array ( [0] => ADMINISTER [1] => EDIT_PROFILE [2] => CREATE_CONTENT [3] => MODERATE_CONTENT [4] => CREATE_ADS [5] => BASIC_ADMIN ) [id] => 35645645678735 ) [1] => stdClass Object ( [category] => Entertainment website [name] => Page 123 [access_token] => abcdefghijklmnopqrstuvwxyz1234567890 [perms] => Array ( [0] => ADMINISTER [1] => EDIT_PROFILE [2] => CREATE_CONTENT [3] => MODERATE_CONTENT [4] => CREATE_ADS [5] => BASIC_ADMIN ) [id] => 1364564569777454 )
How can I get the above into a PHP array? For example to be able to extract the access_token of page id 1364564569777454.
$responsez->data[0]->idorresponsez['data']['0']['id']when$responsez = json_decode(file_get_contents($response), true)[name] => PAGE ABCYou'll want to do a loop, to return the array that has that specific attribute.