Skip to content

Instantly share code, notes, and snippets.

@nicholasdunbar
Last active August 29, 2015 13:56
Show Gist options
  • Save nicholasdunbar/8809636 to your computer and use it in GitHub Desktop.
Save nicholasdunbar/8809636 to your computer and use it in GitHub Desktop.
This extracts the user IDs that were sent an fb app request using the JavaScript Facebook API
//This code is depricated, with the release of the PHP GRAPH LIB v4.0, still the API calls for getting userIDs is very similar.
//This parses the data generated in this piece of code https://gist.github.com/nicholasdunbar/8809354
public function getUserIDsFromRequests($sentRequestsStr){
$config = Zend_Registry::get ( 'config' );
$sentRequestsArray = explode(",", $sentRequestsStr);
$sentRequestsLen = count ( $sentRequestsArray );
$sentUsersStr = "";
if ($config->isFacebookApp){
$facebook = new Facebook(array(
'appId' => $config->appID,
'secret' => $config->appSecretKey,
'cookie' => true
));
for ($i = 0; $i < $sentRequestsLen; $i++){
$cmd = "/".$sentRequestsArray[$i]."/";
//echo $cmd."\n";
try{
$result = $facebook->api($cmd);
//echo "success\n";
if ($result['to']['id']){
$sentUsersStr .= $result['to']['id'];
if ($i < $sentRequestsLen-1){
$sentUsersStr .= ",";
}
}
//print_r($result);
//exit();
//echo "\n";
} catch (FacebookApiException $e) {
//$this->_logger->log ( $result, Zend_Log::INFO );
//print_r($e);
}
}
return $sentUsersStr;
}
}
//To better understand how to use this code check out the following blog article:
//http://www.actionscript-flash-guru.com/blog/43-list-of-user-ids-from-requests-dialog-migrating-from-fbrequest-form-to-fbui-apprequests-facebook-api-javascript-php-.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment