/**
  * Analyzes the supplied result to see if it was thrown
  * because the access token is no longer valid.  If that is
  * the case, then we destroy the session.
  *
  * @param $result array A record storing the error message returned
  *                      by a failed API call.
  */
 protected function throwAPIException($result)
 {
     $e = new FacebookApiException($result);
     switch ($e->getType()) {
         // OAuth 2.0 Draft 00 style
         case 'OAuthException':
             // OAuth 2.0 Draft 10 style
         // OAuth 2.0 Draft 10 style
         case 'invalid_token':
             // REST server errors are just Exceptions
         // REST server errors are just Exceptions
         case 'Exception':
             $message = $e->getMessage();
             if (strpos($message, 'Error validating access token') !== false || strpos($message, 'Invalid OAuth access token') !== false || strpos($message, 'An active access token must be used') !== false) {
                 $this->destroySession();
             }
             break;
     }
     throw $e;
 }
Exemplo n.º 2
0
  /**
   * Analyzes the supplied result to see if it was thrown
   * because the access token is no longer valid.  If that is
   * the case, then the persistent store is cleared.
   *
   * @param $result array A record storing the error message returned
   *                      by a failed API call.
   */
  protected function throwAPIException($result) {
    $e = new FacebookApiException($result);
    switch ($e->getType()) {
      // OAuth 2.0 Draft 00 style
      case 'OAuthException':
        // OAuth 2.0 Draft 10 style
      case 'invalid_token':
        $message = $e->getMessage();
      if ((strpos($message, 'Error validating access token') !== false) ||
          (strpos($message, 'Invalid OAuth access token') !== false)) {
        $this->setAccessToken(null);
        $this->user = 0;
        $this->clearAllPersistentData();
      }
    }

    throw $e;
  }
Exemplo n.º 3
0
 /**
  * Invoke the Graph API.
  *
  * @param String $path the path (required)
  * @param String $method the http method (default 'GET')
  * @param Array $params the query/post data
  * @return the decoded response object
  * @throws FacebookApiException
  */
 protected function _graph($path, $method = 'GET', $params = array())
 {
     if (is_array($method) && empty($params)) {
         $params = $method;
         $method = 'GET';
     }
     $params['method'] = $method;
     // method override as we always do a POST
     $result = json_decode($this->_oauthRequest($this->getUrl('graph', $path), $params), true);
     // results are returned, errors are thrown
     if (is_array($result) && isset($result['error'])) {
         $e = new FacebookApiException($result);
         switch ($e->getType()) {
             // OAuth 2.0 Draft 00 style
             case 'OAuthException':
                 // OAuth 2.0 Draft 10 style
             // OAuth 2.0 Draft 10 style
             case 'invalid_token':
                 $this->setSession(null);
         }
         throw $e;
     }
     return $result;
 }
Exemplo n.º 4
0
 public function testExceptionTypeDefault()
 {
     $e = new FacebookApiException(array('error' => false));
     $this->assertEquals('Exception', $e->getType());
 }
Exemplo n.º 5
0
 /**
  * Invoke the Graph API.
  *
  * @param String $path the path (required)
  * @param String $method the http method (default 'GET')
  * @param Array $params the query/post data
  * @return the decoded response object
  * @throws FacebookApiException
  */
 protected function _graph($path, $method = 'GET', $params = array())
 {
     if (is_array($method) && empty($params)) {
         $params = $method;
         $method = 'GET';
     }
     $params['method'] = $method;
     // method override as we always do a POST
     $result = json_decode($this->_oauthRequest($this->getUrl('graph', $path), $params), true);
     // results are returned, errors are thrown
     if (is_array($result) && isset($result['error'])) {
         $e = new FacebookApiException($result);
         if ($e->getType() === 'OAuthException') {
             $this->setSession(null);
         }
         throw $e;
     }
     /*echo '<pre>';
       print_r($params);
       print_r($result);
       echo '</pre>';
       die();*/
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Invoke the Graph API.
  *
  * @param String $path the path (required)
  * @param String $method the http method (default 'GET')
  * @param Array $params the query/post data
  * @return the decoded response object
  * @throws FacebookApiException
  */
 protected function _graph($path, $method = 'GET', $params = array())
 {
     if (is_array($method) && empty($params)) {
         $params = $method;
         $method = 'GET';
     }
     $params['method'] = $method;
     // method override as we always do a POST
     $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
     $result = $json->decode($this->_oauthRequest($this->getUrl('graph', $path), $params), true);
     // results are returned, errors are thrown
     if (is_array($result) && isset($result['error'])) {
         $e = new FacebookApiException($result);
         if ($e->getType() === 'OAuthException') {
             $this->setSession(null);
         }
         throw $e;
     }
     return $result;
 }