Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pagination for user liked #174

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
32 changes: 22 additions & 10 deletions src/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Instagram
*
* @var string[]
*/
private $_scopes = array('basic', 'likes', 'comments', 'relationships');
private $_scopes = array('basic', 'likes', 'comments', 'relationships', 'public_content', 'follower_list');

/**
* Available actions.
Expand All @@ -86,6 +86,12 @@ class Instagram
* @var int
*/
private $_xRateLimitRemaining;

/**
* Last API Call HTTP Status Code.
* @var int
*/
protected $_httpCode;

/**
* Default constructor.
Expand Down Expand Up @@ -157,14 +163,9 @@ public function searchUser($name, $limit = 0)
*
* @return mixed
*/
public function getUser($id = 0)
public function getUser($id = 'self')
{
$auth = false;

if ($id === 0 && isset($this->_accesstoken)) {
$id = 'self';
$auth = true;
}
$auth = isset($this->_accesstoken);

return $this->_makeCall('users/' . $id, $auth);
}
Expand Down Expand Up @@ -530,6 +531,8 @@ public function pagination($obj, $limit = 0)

if (isset($obj->pagination->next_max_id)) {
return $this->_makeCall($function, $auth, array('max_id' => $obj->pagination->next_max_id, 'count' => $limit));
} elseif (isset($obj->pagination->next_max_like_id)) {
return $this->_makeCall($function, $auth, array('max_like_id' => $obj->pagination->next_max_like_id, 'count' => $limit));
}

return $this->_makeCall($function, $auth, array('cursor' => $obj->pagination->next_cursor, 'count' => $limit));
Expand Down Expand Up @@ -630,12 +633,12 @@ protected function _makeCall($function, $auth = false, $params = null, $method =
$headers = $this->processHeaders($headerContent);

// get the 'X-Ratelimit-Remaining' header value
$this->_xRateLimitRemaining = $headers['X-Ratelimit-Remaining'];
$this->_xRateLimitRemaining = (isset($headers['X-Ratelimit-Remaining'])) ? $headers['X-Ratelimit-Remaining'] : '';

if (!$jsonData) {
throw new InstagramException('Error: _makeCall() - cURL error: ' . curl_error($ch));
}

$this->_httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

return json_decode($jsonData);
Expand Down Expand Up @@ -826,4 +829,13 @@ public function setSignedHeader($signedHeader)
{
$this->_signedheader = $signedHeader;
}

/**
* Last API Call HTTP Status Code Getter.
* @return int
*/
public function getHttpCode()
{
return $this->_httpCode;
}
}