• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    PHP
  • Created over 13 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CodeIgniter PHP Library for interfacing with the Instagram API
No Longer Maintained

As the Instagram API has been stopped this library is no longer maintained.

CodeIgniter library to interact with the Instagram API

Clone the git repository and copy the files to your CodeIgniter application. The library uses Jamie Rumbelow's MY_input.php class to allow ? in CodeIgniter URLs. For more information visit http://www.jamierumbelow.net and see the MY_Input.php file included in application/libraries

You will need to set up a new client with Instagram at http://instagram.com/developer/

Once this is complete copy the details supplied by Instagram into application/config/Instagram_api.php

To use the library add $this->load->library('instagram_api'); to any class or function in your desired controller.

All Instagram API functions, apart from getPopularMedia(), require an access token which Instagram supplies through OAuth.

To set the access token in the Instagram API class use

$this->instagram_api->access_token = YOUR_ACCESS_TOKEN;

after you have loaded the library.

Sample of the functions can be seen at

http://ianluckraft.co.uk/demonstrations/instagram-library/welcome/

I will release this application soon for download as a reference of how to use some of the functions.

/***************************************** Methods ******************************************************/

instagramLogin()

This function creates the url to login with
@return string Instagram login url


    
    /*
     * The authorize function to get the OAuth token
     * Accepts a code that is returned from Instagram to our redirect url
     * @param string code generated by Instagram when the user has been sent to our redirect url
     * @return std_class Instagram OAuth data
     */
	function authorize($code)
	{
	
		$authorization_url = 'https://api.instagram.com/oauth/access_token';
		
		return $this->__apiCall($authorization_url, "client_id=" . $this->codeigniter_instance->config->item('instagram_client_id') . "&client_secret=" . $this->codeigniter_instance->config->item('instagram_client_secret') . "&grant_type=authorization_code&redirect_uri=" . $this->codeigniter_instance->config->item('instagram_callback_url') . "&code=" . $code);		
		
	}
    
    /*
     * Get a list of what media is most popular at the moment
     * This function only requires your instagram client id and no Oauth token
     * @return std_class current popular media with associated data
     */
    function getPopularMedia()
    {
        
    	$popular_media_request_url = 'https://api.instagram.com/v1/media/popular?client_id=' . $this->codeigniter_instance->config->item('instagram_client_id');
    	
    	return $this->__apiCall($popular_media_request_url);
        
    }
    
    /*
     * Get an individual user's details
     * Accepts a user id
     * @param int Instagram user id
     * @return std_class data about the Instagram user
     */
    function getUser($user_id) {
    	
    	$user_request_url = sprintf($this->api_urls['user'], $user_id, $this->access_token);
    	
    	return $this->__apiCall($user_request_url);
    	
    }
    
    http://instagram.com/developer/endpoints/users/#get_users
    
    /*
     * Get an individual user's feed
     * Accepts optional max and min values
     * @param int return media after max id
     * @param int return media before min id
     * @return std_class of user's feed
     */
    function getUserFeed($max = null, $min = null) {
    	
    	$user_feed_request_url = sprintf($this->api_urls['user_feed'], $this->access_token, $max, $min);
    	
    	return $this->__apiCall($user_feed_request_url);
    	
    }
    
    http://instagram.com/developer/endpoints/users/#get_users_feed
    
    /*
     * Function to get a users recent published media
     * Accepts a user id and access token and optional max id, min id, max timestamp and min timestamp
     * @param int Instagram user id
     * @param int return media after max id
     * @param int return media before min id
     * @param int return media after this UNIX timestamp
     * @param int return media before this UNIX timestamp
     * @return std_class of media found based on parameters given
     */
    function getUserRecent($user_id, $max_id = null, $min_id = null, $max_timestamp = null, $min_timestamp = null) {
    	
    	$user_recent_request_url = sprintf($this->api_urls['user_recent'], $user_id, $this->access_token, $max_id, $min_id, $max_timestamp, $min_timestamp);
    	
    	return $this->__apiCall($user_recent_request_url);
    	
    }
    
    /*
     * Function to search for user
     * Accepts a user name to search for
     * @param string an Instagram user name
     * @return std_class user data
     */
    function userSearch($user_name) {
    	
    	$user_search_request_url = sprintf($this->api_urls['user_search'], $user_name, $this->access_token);
    	
    	return $this->__apiCall($user_search_request_url);
    	
    }
    
    /*
     * Function to get all users the current user follows
     * Accepts a user id
     * @param int user id
     * @return std_class user's recent feed items
     */
    function userFollows($user_id) {
    	
    	$user_follows_request_url = sprintf($this->api_urls['user_follows'], $user_id, $this->access_token);
    	
    	return $this->__apiCall($user_follows_request_url);
    	
    }
    
    /*
     * Function to get all users the current user follows
     * Accepts a user id
     * @param int user id
     * @return std_class other users that follow the one passed in
     */
    function userFollowedBy($user_id) {
    	
    	$user_followed_by_request_url = sprintf($this->api_urls['user_followed_by'], $user_id, $this->access_token);
    	
    	return $this->__apiCall($user_followed_by_request_url);
    	
    }
    
    /*
     * Function to find who a user was requested by
     * Accepts an access token
     * @return std_class users who have requested this user's permission to follow
     */
    function userRequestedBy() {
    	
    	$user_requested_by_request_url = sprintf($this->api_urls['user_requested_by'], $this->access_token);
    	
    	return $this->__apiCall($user_requested_by_request_url);
    	
    }
    
    /*
     * Function to get information about the current user's relationship (follow/following/etc) to another user
     * @param int user id
     * @return std_class user's relationship to another user
     */
    function userRelationship($user_id) {
    	
    	$user_relationship_request_url = sprintf($this->api_urls['user_relationship'], $user_id, $this->access_token);
    	
    	return $this->__apiCall($user_relationship_request_url);
    	
    }
    
	/*
     * Function to modify the relationship between the current user and the target user
     * @param int Instagram user id
     * @param string action to effect relatonship (follow/unfollow/block/unblock/approve/deny)
     * @return std_class result of request
     */
    function modifyUserRelationship($user_id, $action) {
    	
    	$user_modify_relationship_request_url = sprintf($this->api_urls['modify_user_relationship'], $user_id, $action, $this->access_token);
    	
    	return $this->__apiCall($user_modify_relationship_request_url);
    	
    }
    
    /*
     * Function to get data about a media id
     * Accepts a media id
     * @param int media id
     * @return std_class data about the media item
     */
    function getMedia($media_id) {
    	
    	$media_request_url = sprintf($this->api_urls['media'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($media_request_url);
    	
    }
    
    /*
     * Function to search for media
     * Accepts optional parameters
     * @param int latitude
     * @param int longitude
     * @param int max timestamp
     * @param int min timestamp
     * @param int distance
     * @return std_class media items found in search
     */
    function mediaSearch($latitude = null, $longitude = null, $max_timestamp = null, $min_timestamp = null, $distance = null) {
    	
    	$media_search_request_url = sprintf($this->api_urls['media_search'], $latitude, $longitude, $max_timestamp, $min_timestamp, $distance, $this->access_token);
    	
    	return $this->__apiCall($media_search_request_url);
    	
    }
    
    /*
     * Function to get a list of what media is most popular at the moment
     * @return std_class popular media
     */
    function popularMedia() {
    	
    	$popular_media_request_url = sprintf($this->api_urls['media_popular'], $this->access_token);
    	
    	return $this->__apiCall($popular_media_request_url);
    	
    }
    
    /*
     * Function to gget a full list of comments on a media
     * @param int media id
     * @return std_class media comments
     */
    function mediaComments($media_id) {
    
    	$media_comments_request_url = sprintf($this->api_urls['media_comments'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($media_comments_request_url);
    
    }
    
    /*
     * Function to post a media comment
     * @param int media id
     * @return std_class response to request
     */
    function postMediaComment($media_id) {
    
    	/********* NEED TO LOOK INTO THIS FURTHER *************/
    
    	/*$post_media_comment_url = sprintf($this->api_urls['post_media_comment'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($post_media_comment_url);*/    	
    
    }
    
    /*
     * Function to delete a media comment
     * @param int media id
     * @param int comment id
     * @return std_class response to request
     */
    function deleteMediaComment($media_id, $comment_id) {
    
    	$delete_media_comment_url = sprintf($this->api_urls['delete_media_comment'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($delete_media_comment_url);
    
    }
    
    /*
     * Function to get a list of users who have liked this media
     * @param int media id
     * @return std_class list of users
     */
    function mediaLikes($media_id) {
    
    	$media_likes_request_url = sprintf($this->api_urls['likes'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($media_likes_request_url);
    
    }
    
    /*
     * Function to post a like for a media item
     * @param int media id
     * @return std_class response to request
     */
    function postLike($media_id) {
    
        $post_media_like_request_url = sprintf($this->api_urls['post_like'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($post_media_like_request_url);
    
    }

	/*
	 * Function to remove a like for a media item
	 * @param int media id
	 * @return std_class response to request
	 */
    function removeLike($media_id) {
    
    	$remove_like_request_url = sprintf($this->api_urls['remove_like'], $media_id, $this->access_token);
    	
    	return $this->__apiCall($remove_like_request_url);
    	
    }
    
    /*
     * Function to get information about a tag object
     * @param string tag
     * @return std_class of data about the tag
     */
    function getTags($tag) {
    
    	$tags_request_url = sprintf($this->api_urls['tags'], $tag, $this->access_token);
    	
    	return $this->__apiCall($tags_request_url);
    
    }
    
    /*
     * Function to get a list of recently tagged media
     * @param string tag
     * @param int return media after this max_id
     * @param int return media before this min_id
     * @return std_class recently tagged media
     */
    function tagsRecent($tag, $max_id = null, $min_id = null) {
    
    	$tags_recent_request_url = sprintf($this->api_urls['tags_recent'], $tag, $max_id, $min_id, $this->access_token);
    	
    	return $this->__apiCall($tags_recent_request_url);
    
    }
    
	/*
     * Function to search for tagged media
     * @param string valid tag name without a leading #. (eg. snow, nofilter)
     * @return std_class tags by name - results are ordered first as an exact match, then by popularity
     */
    function tagsSearch($tag) {
    
    	$tags_search_request_url = sprintf($this->api_urls['tags_search'], $tag, $this->access_token);
    	
    	return $this->__apiCall($tags_search_request_url);
    
    }
    
    /*
     * Function to get information about a location. 
     * @param int location id
     * @return std_class data about the location
     */
    function getLocation($location) {
    
    	$location_request_url = sprintf($this->api_urls['locations'], $location, $this->access_token);
    	
    	return $this->__apiCall($location_request_url);
    
    }
    
    /*
     * Function to get a list of recent media objects from a given location.
     * @param int location id
     * @param int return media after this max_id
     * @param int return media before this min_id
     * @param int return media after this UNIX timestamp
     * @param int return media before this UNIX timestamp
     * @return std_class recent media objects from a location
     */
    function locationRecent($location, $max_id = null, $min_id = null, $max_timestamp = null, $min_timestamp = null) {
    
    	$location_recent_request_url = sprintf($this->api_urls['locations_recent'], $location, $max_id, $min_id, $max_timestamp, $min_timestamp, $this->access_token);
    	
    	return $this->__apiCall($location_recent_request_url);
    
    }
    
    /*
     * Function to search for locations used in Instagram
     * @param int latitude of the center search coordinate. If used, longitude is required
     * @param int longitude of the center search coordinate. If used, latitude is required
     * @param int Foursquare id. Returns a location mapped off of a foursquare v1 api location id. If used, you are not required to use lat and lng. Note that this method will be deprecated over time and transitioned to new foursquare IDs with V2 of their API.
     * @param int distance. Default is 1000m (distance=1000), max distance is 5000
     * @return std_class location data
     */
    function locationSearch($latitude = null, $longitude = null, $foursquare_id = null, $distance = null) {
    
    	$location_search_request_url = sprintf($this->api_urls['locations_search'], $latitude, $longitude, $foursquare_id, $distance, $this->access_token);
    	
    	return $this->__apiCall($location_search_request_url);
    
    }

}