Example #1
0
 /**
  * Generate and return the URL for this request.
  *
  * @return string
  */
 public function getUrl()
 {
     $this->validateMethod();
     $graphVersion = FacebookUrlManipulator::forceSlashPrefix($this->graphVersion);
     $endpoint = FacebookUrlManipulator::forceSlashPrefix($this->getEndpoint());
     $url = $graphVersion . $endpoint;
     if ($this->getMethod() !== 'POST') {
         $params = $this->getParams();
         $url = FacebookUrlManipulator::appendParamsToUrl($url, $params);
     }
     return $url;
 }
Example #2
0
 /**
  * Generates a pagination URL based on a cursor.
  *
  * @param string $direction The direction of the page: next|previous
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function getPaginationUrl($direction)
 {
     $this->validateForPagination();
     // Do we have a paging URL?
     if (!isset($this->metaData['paging'][$direction])) {
         return null;
     }
     $pageUrl = $this->metaData['paging'][$direction];
     return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
 }
 /**
  * Generates a pagination URL based on a cursor.
  *
  * @param string $direction The direction of the page: next|previous
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function getPaginationUrl($direction)
 {
     $this->validateForPagination();
     // Do we have a paging URL?
     if (isset($this->metaData['paging'][$direction])) {
         // Graph returns the full URL with all the original params.
         // We just want the endpoint though.
         $pageUrl = $this->metaData['paging'][$direction];
         return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
     }
     // Do we have a cursor to work with?
     $cursorDirection = $direction === 'next' ? 'after' : 'before';
     $cursor = $this->getCursor($cursorDirection);
     if (!$cursor) {
         return null;
     }
     // If we don't know the ID of the parent node, this ain't gonna work.
     if (!$this->parentEdgeEndpoint) {
         return null;
     }
     // We have the parent node ID, paging cursor & original request.
     // These were the ingredients chosen to create the perfect little URL.
     $pageUrl = $this->parentEdgeEndpoint . '?' . $cursorDirection . '=' . urlencode($cursor);
     // Pull in the original params
     $originalUrl = $this->request->getUrl();
     $pageUrl = FacebookUrlManipulator::mergeUrlParams($originalUrl, $pageUrl);
     return FacebookUrlManipulator::forceSlashPrefix($pageUrl);
 }
 /**
  * Takes a valid code from a login redirect, and returns an AccessToken entity.
  *
  * @param string|null $redirectUrl The redirect URL.
  *
  * @return AccessToken|null
  *
  * @throws FacebookSDKException
  */
 public function getAccessToken($redirectUrl = null)
 {
     if (!($code = $this->getCode())) {
         return null;
     }
     $this->validateCsrf();
     $redirectUrl = $redirectUrl ?: $this->urlDetectionHandler->getCurrentUrl();
     // At minimum we need to remove the state param
     $redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['state']);
     return $this->oAuth2Client->getAccessTokenFromCode($code, $redirectUrl);
 }
 public function testGraphUrlsCanBeTrimmed()
 {
     $fullGraphUrl = 'https://graph.facebook.com/';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/v1.0/';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.beta.facebook.com/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://whatever-they-want.facebook.com/v2.1/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/v5.301/1233?foo=bar';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/1233?foo=bar', $baseGraphUrl);
 }