Skip to content

Commit 26ae9f1

Browse files
committed
Merge branch 'get_user_pages'
2 parents 401b56e + ca0da8a commit 26ae9f1

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/Instagram/Instagram.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ public function setPrevNextLinks( &$response ) {
221221
public function setAccessToken( $accessToken ) {
222222
$this->accessToken = $accessToken;
223223
}
224+
225+
/**
226+
* Calculate next link based on the cursors.
227+
*
228+
* @param string $type type of link after or before.
229+
* @param array $response Instagram api response.
230+
* @param array $params specific request params.
231+
* @return void
232+
*/
233+
public function calcLinkFromCursor( $type, &$response, $endpoint, $params ) {
234+
if ( isset( $response[Fields::PAGING][Fields::CURSORS][$type] ) ) { // we have paging
235+
// set the after cursor
236+
$params[$type] = $response[Fields::PAGING][Fields::CURSORS][$type];
237+
238+
// create our request
239+
$request = new Request( Request::METHOD_GET, $endpoint, $params, $this->graphVersion, $this->accessToken );
240+
241+
// set paging type based
242+
$pagingOrder = Params::AFTER == $type ? Params::NEXT : Params::PREVIOUS;
243+
244+
// set paging next to the url for the next request
245+
$response[Fields::PAGING][$pagingOrder] = $request->getUrl();
246+
}
247+
}
224248
}
225249

226250
?>

src/Instagram/Request/Params.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
class Params {
3838
const ACCESS_TOKEN = 'access_token';
3939
const AFTER = 'after';
40+
const BEFORE = 'before';
4041
const CAPTION = 'caption';
4142
const CHILDREN = 'children';
4243
const CLIENT_ID = 'client_id';

src/Instagram/User/User.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
* @version 1.0
4343
*/
4444
class User extends Instagram {
45+
/**
46+
* @const Instagram endpoint for the request.
47+
*/
48+
const ENDPOINT = 'me/accounts';
49+
4550
/**
4651
* @var string $userId Instagram user id.
4752
*/
@@ -95,6 +100,34 @@ public function getSelf( $params = array() ) {
95100
// return response
96101
return $response;
97102
}
103+
104+
/**
105+
* Get the users facebook pages.
106+
*
107+
* @param array $params params for the GET request.
108+
* @return Instagram response.
109+
*/
110+
public function getUserPages( $params = array() ) {
111+
$getParams = array( // parameters for our endpoint
112+
'endpoint' => '/' . self::ENDPOINT,
113+
'params' => $params
114+
);
115+
116+
// ig get request
117+
$response = $this->get( $getParams );
118+
119+
// calculate the next link for paging
120+
$this->calcLinkFromCursor( Params::AFTER, $response, $getParams['endpoint'], $params );
121+
122+
// calcuate the before link
123+
$this->calcLinkFromCursor( Params::BEFORE, $response, $getParams['endpoint'], $params );
124+
125+
// set prev and next links
126+
$this->setPrevNextLinks( $response );
127+
128+
// return response
129+
return $response;
130+
}
98131
}
99132

100133
?>

0 commit comments

Comments
 (0)