Jump to content

Recommended Posts

i am trying to load the current users images from instagrams api. i got there user id and other things but i cant seem to get the recent media that they posted ... here is the codes im using

 

 protected $_endpointUrls = array(
    'authorize' => 'https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=%s',
    'access_token' => 'https://api.instagram.com/oauth/access_token',
    'user' => 'https://api.instagram.com/v1/users/%d/?access_token=%s',
    'user_feed' => 'https://api.instagram.com/v1/users/self/feed?%s',
    'user_recent' => 'https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s&max_id=%s&min_id=%s&max_timestamp=%s&min_timestamp=%s',);

 

public function getUserRecent($id, $maxId = '', $minId = '', $maxTimestamp = '', $minTimestamp = '') {
    $endpointUrl = sprintf($this->_endpointUrls['user_recent'], $id, $this->getAccessToken(), $maxId, $minId, $maxTimestamp, $minTimestamp);
    $this->_initHttpClient($endpointUrl);
    return $this->_getHttpClientResponse();
   }

 

this is where i call upon those two to get the users photos but it wont display them

 

<? $userphotos = $instagram-> getUserRecent($_SESSION['InstagramAccessToken']);

$photos = json_decode($userphotos, true);




?>

<?= $photos['data']['user']['user_recent'] ?>

Link to comment
https://forums.phpfreaks.com/topic/271881-api-help/
Share on other sites

this is what happens in gethttpclientresponst()

class CurlHttpClient {
   /**
 * Default User-Agent
 * @var string
 */
   const DEFAULT_USER_AGENT = '';
   /**
 * Used HTTP request methods
 */
   const GET = 'GET';
   const POST = 'POST';
   const DELETE = 'DELETE';
   /**
 * cURL handler
 * @var resource
 */
   private $handler;
   /**
 * Store the POST fields
 */
   private $postParams = array();
   /**
 * Initiate a cURL session
 * @param string $url
 */
   public function __construct($uri) {
    $this->handler = curl_init($uri);
    $this->_setOptions();
   }
   protected function _setOptions() {
    curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($this->handler, CURLOPT_USERAGENT, self::DEFAULT_USER_AGENT);
   }
   /**
 * Set the URI
 * @param $uri
 */
   public function setUri($uri) {
    $this->handler = curl_init($uri);
    $this->_setOptions();
   }
   /**
 * Receive the response with full headers
 * @param boolean $value
 */
   public function setHeaders($value = true) {
    curl_setopt($this->handler, CURLOPT_HEADER, $value);
   }
   /**
 * Set the HTTP request method
 * @param string $method
 */
   public function setMethod($method = self::GET) {
    switch ($method) {
	    case self::GET :
		    curl_setopt($this->handler, CURLOPT_HTTPGET, true);
		    break;
	    case self::POST :
		    curl_setopt($this->handler, CURLOPT_POST, true);
		    break;
	    case self::DELETE :
		    curl_setopt($this->handler, CURLOPT_CUSTOMREQUEST, self::DELETE);
		    break;
	    default:
		    throw new CurlHttpClientException('Method not supported');
    }
   }
   /**
 * Add a new post param to the set
 * @param string $name
 * @param mixed $value
 */
   public function setPostParam($name, $value) {
    $this->postParams[$name] = $value;
    curl_setopt($this->handler, CURLOPT_POSTFIELDS, $this->postParams);
   }
   /**
 * Get the response
 * @return string
 */
   public function getResponse() {
    $response = curl_exec($this->handler);
    curl_close($this->handler);
    return $response;
   }
   /**
 * Extract the headers from a response string
 *
 * @param string $response
 * @return mixed[]
 */
   protected function extractHeaders($response) {
    $headers = array();
    // First, split body and headers
    $parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
    if (!$parts[0]) return $headers;
    // Split headers part to lines
    $lines = explode("\n", $parts[0]);
    unset($parts);
    $last_header = null;
    foreach($lines as $line) {
	    $line = trim($line, "\r\n");
	    if ($line == "") break;
	    // Locate headers like 'Location: ...' and 'Location:...' (note the missing space)
	    if (preg_match("|^([\w-]+):\s*(.+)|", $line, $m)) {
		    unset($last_header);
		    $h_name = strtolower($m[1]);
		    $h_value = $m[2];
		    if (isset($headers[$h_name])) {
			    if (! is_array($headers[$h_name])) {
				    $headers[$h_name] = array($headers[$h_name]);
			    }
			    $headers[$h_name][] = $h_value;
		    } else {
			    $headers[$h_name] = $h_value;
		    }
		    $last_header = $h_name;
	    } else if (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
		    if (is_array($headers[$last_header])) {
			    end($headers[$last_header]);
			    $last_header_key = key($headers[$last_header]);
			    $headers[$last_header][$last_header_key] .= $m[1];
		    } else {
			    $headers[$last_header] .= $m[1];
		    }
	    }
    }
    return $headers;
   }
}
class CurlHttpClientException extends Exception {}

 

here is what endpointUrl is

protected $_endpointUrls = array(
    'authorize' => 'https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=%s',
    'access_token' => 'https://api.instagram.com/oauth/access_token',
    'user' => 'https://api.instagram.com/v1/users/%d/?access_token=%s',
    'user_feed' => 'https://api.instagram.com/v1/users/self/feed?%s',
    'user_recent' => 'https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s&max_id=%s&min_id=%s&max_timestamp=%s&min_timestamp=%s',
    'user_search' => 'https://api.instagram.com/v1/users/search?q=%s&access_token=%s',
    'user_follows' => 'https://api.instagram.com/v1/users/%d/follows?access_token=%s&cursor=%s',
    'user_followed_by' => 'https://api.instagram.com/v1/users/%d/followed-by?access_token=%s',
    'user_requested_by' => 'https://api.instagram.com/v1/users/self/requested-by?access_token=%s',
    'user_relationship' => 'https://api.instagram.com/v1/users/%d/relationship?access_token=%s',
    'modify_user_relationship' => 'https://api.instagram.com/v1/users/%d/relationship?action=%s&access_token=%s',
    'media' => 'https://api.instagram.com/v1/media/%d?access_token=%s',
    'media_search' => 'https://api.instagram.com/v1/media/search?lat=%s&lng=%s&max_timestamp=%s&min_timestamp=%s&distance=%s&access_token=%s',
    'media_popular' => 'https://api.instagram.com/v1/media/popular?access_token=%s',
    'media_comments' => 'https://api.instagram.com/v1/media/%d/comments?access_token=%s',
    'post_media_comment' => 'https://api.instagram.com/v1/media/%d/comments?access_token=%s',
    'delete_media_comment' => 'https://api.instagram.com/v1/media/%d/comments?comment_id=%d&access_token=%s',
    'likes' => 'https://api.instagram.com/v1/media/%d/likes?access_token=%s',
    'post_like' => 'https://api.instagram.com/v1/media/%d/likes',
    'remove_like' => 'https://api.instagram.com/v1/media/%d/likes?access_token=%s',
    'tags' => 'https://api.instagram.com/v1/tags/%s?access_token=%s',
    'tags_recent' => 'https://api.instagram.com/v1/tags/%s/media/recent?max_id=%s&min_id=%s&access_token=%s',
    'tags_search' => 'https://api.instagram.com/v1/tags/search?q=%s&access_token=%s',
    'locations' => 'https://api.instagram.com/v1/locations/%d?access_token=%s',
    'locations_recent' => 'https://api.instagram.com/v1/locations/%d/media/recent/?max_id=%s&min_id=%s&max_timestamp=%s&min_timestamp=%s&access_token=%s',
    'locations_search' => 'https://api.instagram.com/v1/locations/search?lat=%s&lng=%s&foursquare_id=%s&distance=%s&access_token=%s',
   );

Just the links for the different things to do on instagram

Link to comment
https://forums.phpfreaks.com/topic/271881-api-help/#findComment-1399277
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.