Closed bassrock closed 10 years ago
Nvm. Did something like this:
$userId = intval($input->getArgument("user_id"));
/** @var \FOS\UserBundle\Model\UserManagerInterface $userManager */
$userManager = $this->getContainer()->get("fos_user.user_manager");
/** @var \UserBundle\Entity\User $user */
$user = $userManager->findUserBy(array("id"=>$userId));
if(is_null($user)) {
$output->writeln("The specified user id does not exist.");
return;
}
$facebookToken = $user->getFacebookToken();
if(is_null($facebookToken)) {
$output->writeln("The specified user facebook token does not exist.");
return;
}
/** @var \FOS\FacebookBundle\Facebook\FacebookSessionPersistence $facebook */
$facebook = $this->getContainer()->get("fos_facebook.api");
$facebook->setAccessToken($user->getFacebookToken());
try {
$fbdata = $facebook->api('/me');
} catch (FacebookApiException $e) {
$fbdata = null;
}
try {
if(!is_null($fbdata)) {
$fbdata2 = $facebook->api('/'.$user->getFacebookId());
$fbdata = array_merge($fbdata,$fbdata2);
}
} catch (FacebookApiException $e) {
}
if (!empty($fbdata)) {
$extended = $facebook->setExtendedAccessToken();
$expirationDate = new \DateTime("now");
if($extended || is_null($extended)) {
$expirationDate->add(new \DateInterval("P60D"));
} else {
$expirationDate->add(new \DateInterval("PT2H"));
}
$user->setFacebookToken($facebook->getAccessToken());
$user->setTokenExpirationDate($expirationDate);
// TODO use http://developers.facebook.com/docs/api/realtime
$user->setFBData($fbdata);
$userManager->updateUser($user);
}
Hi,
I am trying to create a command to extend the users Facebook token and then update their Facebook data with their latest information. How would I go update grabbing a Facebook object for a specific User object from my database?
Thanks in advance!