diff --git a/src/Instagram/Instagram.php b/src/Instagram/Instagram.php index fcd5963..9539cd8 100644 --- a/src/Instagram/Instagram.php +++ b/src/Instagram/Instagram.php @@ -221,6 +221,30 @@ public function setPrevNextLinks( &$response ) { public function setAccessToken( $accessToken ) { $this->accessToken = $accessToken; } + + /** + * Calculate next link based on the cursors. + * + * @param string $type type of link after or before. + * @param array $response Instagram api response. + * @param array $params specific request params. + * @return void + */ + public function calcLinkFromCursor( $type, &$response, $endpoint, $params ) { + if ( isset( $response[Fields::PAGING][Fields::CURSORS][$type] ) ) { // we have paging + // set the after cursor + $params[$type] = $response[Fields::PAGING][Fields::CURSORS][$type]; + + // create our request + $request = new Request( Request::METHOD_GET, $endpoint, $params, $this->graphVersion, $this->accessToken ); + + // set paging type based + $pagingOrder = Params::AFTER == $type ? Params::NEXT : Params::PREVIOUS; + + // set paging next to the url for the next request + $response[Fields::PAGING][$pagingOrder] = $request->getUrl(); + } + } } ?> \ No newline at end of file diff --git a/src/Instagram/Request/Params.php b/src/Instagram/Request/Params.php index d4ebd93..adadde6 100644 --- a/src/Instagram/Request/Params.php +++ b/src/Instagram/Request/Params.php @@ -37,6 +37,7 @@ class Params { const ACCESS_TOKEN = 'access_token'; const AFTER = 'after'; + const BEFORE = 'before'; const CAPTION = 'caption'; const CHILDREN = 'children'; const CLIENT_ID = 'client_id'; diff --git a/src/Instagram/User/User.php b/src/Instagram/User/User.php index b60d325..b4f1e5c 100644 --- a/src/Instagram/User/User.php +++ b/src/Instagram/User/User.php @@ -42,6 +42,11 @@ * @version 1.0 */ class User extends Instagram { + /** + * @const Instagram endpoint for the request. + */ + const ENDPOINT = 'me/accounts'; + /** * @var string $userId Instagram user id. */ @@ -95,6 +100,34 @@ public function getSelf( $params = array() ) { // return response return $response; } + + /** + * Get the users facebook pages. + * + * @param array $params params for the GET request. + * @return Instagram response. + */ + public function getUserPages( $params = array() ) { + $getParams = array( // parameters for our endpoint + 'endpoint' => '/' . self::ENDPOINT, + 'params' => $params + ); + + // ig get request + $response = $this->get( $getParams ); + + // calculate the next link for paging + $this->calcLinkFromCursor( Params::AFTER, $response, $getParams['endpoint'], $params ); + + // calcuate the before link + $this->calcLinkFromCursor( Params::BEFORE, $response, $getParams['endpoint'], $params ); + + // set prev and next links + $this->setPrevNextLinks( $response ); + + // return response + return $response; + } } ?> \ No newline at end of file