Exemple #1
0
 /**
  * Link the user with Facebook details.
  *
  * @param string $id the Facebook user identifier
  * @param string $access_token the access token for this session
  * @param \DateTime $expiration_date defaults to 60 days
  * @param boolean $useMasterKey whether to override security
  *
  * @throws ParseException
  *
  * @return ParseUser
  */
 public function linkWithFacebook($id, $access_token, $expiration_date = null, $useMasterKey = false)
 {
     if (!$this->getObjectId()) {
         throw new ParseException("Cannot link an unsaved user, use ParseUser::logInWithFacebook");
     }
     if (!$id) {
         throw new ParseException("Cannot link Facebook user without an id.");
     }
     if (!$access_token) {
         throw new ParseException("Cannot link Facebook user without an access token.");
     }
     if (!$expiration_date) {
         $expiration_date = new \DateTime();
         $expiration_date->setTimestamp(time() + 86400 * 60);
     }
     $data = ["authData" => ["facebook" => ["id" => $id, "access_token" => $access_token, "expiration_date" => ParseClient::getProperDateFormat($expiration_date)]]];
     $result = ParseClient::_request("PUT", "/1/users/" . $this->getObjectId(), $this->getSessionToken(), json_encode($data), $useMasterKey);
     $user = new ParseUser();
     $user->_mergeAfterFetch($result);
     $user->handleSaveResult(true);
     return $user;
 }
 /**
  * Link the user with Facebook details.
  *
  * @param string    $id              the Facebook user identifier
  * @param string    $access_token    the access token for this session
  * @param \DateTime $expiration_date defaults to 60 days
  * @param bool      $useMasterKey    whether to override security
  *
  * @throws ParseException
  *
  * @return ParseUser
  */
 public function linkWithFacebook($id, $access_token, $expiration_date = null, $useMasterKey = false)
 {
     if (!$this->getObjectId()) {
         throw new ParseException('Cannot link an unsaved user, use ParseUser::logInWithFacebook');
     }
     if (!$id) {
         throw new ParseException('Cannot link Facebook user without an id.');
     }
     if (!$access_token) {
         throw new ParseException('Cannot link Facebook user without an access token.');
     }
     if (!$expiration_date) {
         $expiration_date = new \DateTime();
         $expiration_date->setTimestamp(time() + 86400 * 60);
     }
     $data = array('authData' => array('facebook' => array('id' => $id, 'access_token' => $access_token, 'expiration_date' => ParseClient::getProperDateFormat($expiration_date))));
     $result = ParseClient::_request('PUT', 'users/' . $this->getObjectId(), $this->getSessionToken(), json_encode($data), $useMasterKey);
     $user = new self();
     $user->_mergeAfterFetch($result);
     $user->handleSaveResult(true);
     return $user;
 }