├── .gitignore ├── LICENSE ├── README.md ├── composer.json └── src └── Instagram ├── AccessToken └── AccessToken.php ├── Comment ├── Comment.php └── Replies.php ├── Container └── Container.php ├── FacebookLogin └── FacebookLogin.php ├── Hashtag ├── Hashtag.php ├── RecentMedia.php └── TopMedia.php ├── HashtagSearch └── HashtagSearch.php ├── Instagram.php ├── Media ├── Children.php ├── Comments.php ├── Insights.php └── Media.php ├── Page └── Page.php ├── Request ├── Curl.php ├── Fields.php ├── GrantTypes.php ├── MediaTypes.php ├── Metric.php ├── Params.php ├── Period.php ├── Request.php ├── ResponseTypes.php ├── Scope.php └── certs │ └── cacert.pem ├── User ├── BusinessDiscovery.php ├── ContentPublishingLimit.php ├── Insights.php ├── LiveMedia.php ├── Media.php ├── MediaPublish.php ├── MentionedComment.php ├── MentionedMedia.php ├── Mentions.php ├── RecentlySearchedHashtags.php ├── Stories.php ├── Tags.php └── User.php └── autoload.php /.gitignore: -------------------------------------------------------------------------------- 1 | #------------------------- 2 | # Composer 3 | #------------------------- 4 | vendor/ 5 | composer.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Justin Stolpe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # instagram-graph-api-php-sdk 2 | 3 | This repository contains the open source PHP SDK that allows you to access the Instagram Graph API from your PHP app. 4 | 5 | ## Installation 6 | 7 | ### Composer 8 | 9 | Run this command: 10 | 11 | ``` 12 | composer require jstolpe/instagram-graph-api-php-sdk 13 | ``` 14 | 15 | Require the the autoloader. 16 | 17 | ```php 18 | require_once __DIR__ . '/vendor/autoload.php'; // change path as needed 19 | ``` 20 | 21 | ### No Composer 22 | 23 | Get the repository 24 | 25 | ``` 26 | git clone git@github.com:jstolpe/instagram-graph-api-php-sdk.git 27 | ``` 28 | 29 | Require the custom autoloader. 30 | 31 | ```php 32 | require_once '/instagram-graph-api-php-sdk/src/instagram/autoload.php'; // change path as needed 33 | ``` 34 | 35 | ## Usage 36 | 37 | Simple GET example of a user's profile and media posts. 38 | ```php 39 | use Instagram\User\BusinessDiscovery; 40 | 41 | $config = array( // instantiation config params 42 | 'user_id' => '', 43 | 'username' => '', // string of the Instagram account username to get data on 44 | 'access_token' => '', 45 | ); 46 | 47 | // instantiate business discovery for a user 48 | $businessDiscovery = new BusinessDiscovery( $config ); 49 | 50 | // initial business discovery 51 | $userBusinessDiscovery = $businessDiscovery->getSelf(); 52 | ``` 53 | 54 | Simple POST example of posting an image to an Instagram account. 55 | ```php 56 | use Instagram\User\Media; 57 | use Instagram\User\MediaPublish; 58 | 59 | $config = array( // instantiation config params 60 | 'user_id' => '', 61 | 'access_token' => '', 62 | ); 63 | 64 | // instantiate user media 65 | $media = new Media( $config ); 66 | 67 | $imageContainerParams = array( // container parameters for the image post 68 | 'caption' => '', // caption for the post 69 | 'image_url' => '', // url to the image must be on a public server 70 | ); 71 | 72 | // create image container 73 | $imageContainer = $media->create( $imageContainerParams ); 74 | 75 | // get id of the image container 76 | $imageContainerId = $imageContainer['id']; 77 | 78 | // instantiate media publish 79 | $mediaPublish = new MediaPublish( $config ); 80 | 81 | // post our container with its contents to instagram 82 | $publishedPost = $mediaPublish->create( $imageContainerId ); 83 | ``` 84 | 85 | Example of a custom request. 86 | ```php 87 | // first we have to instantiate the core Instagram class with our access token 88 | $instagram = new Instagram\Instagram( array( 89 | 'access_token' => '' 90 | ) ); 91 | 92 | /** 93 | * Here we are making our request to instagram and specify the endpoint along with our custom params. 94 | * There is a custom function for get, post, and delete. 95 | * $instagram->get() 96 | * $instagram->post() 97 | * $instagram->delete() 98 | * 99 | * Here is the skeleton for the customized call. 100 | */ 101 | $response = $instagram->method( array( 102 | 'endpoint' => '/', 103 | 'params' => array( // query params key/values must match what IG API is expecting for the endpoint 104 | '' => '', 105 | '' => '', 106 | // ... 107 | ) 108 | ) ); 109 | ``` 110 | 111 | ## Documentation 112 | 113 | See the [Wiki](https://github.com/jstolpe/instagram-graph-api-php-sdk/wiki) for the complete documentation. 114 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jstolpe/instagram-graph-api-php-sdk", 3 | "description": "Instagram Graph API PHP SDK", 4 | "keywords": ["instagram", "api", "graph api", "sdk", "php", "instagram graph api"], 5 | "type": "library", 6 | "homepage": "https://github.com/jstolpe/instagram-graph-api-php-sdk", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Justin Stolpe", 11 | "homepage": "https://github.com/jstolpe/instagram-graph-api-php-sdk" 12 | } 13 | ], 14 | "require": { 15 | "php": "^5.6|^7.0|^8.0" 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Instagram\\": "src/Instagram/" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Instagram/AccessToken/AccessToken.php: -------------------------------------------------------------------------------- 1 | appId = isset( $config['app_id'] ) ? $config['app_id'] : ''; 100 | 101 | // set the application secret 102 | $this->appSecret = isset( $config['app_secret'] ) ? $config['app_secret'] : ''; 103 | 104 | // set the access token 105 | $this->value = isset( $config['value'] ) ? $config['value'] : ''; 106 | 107 | // set the access token expire date 108 | $this->expiresAt = isset( $config['expires_at'] ) ? $config['expires_at'] : $this->expiresAt; 109 | 110 | // set the user id 111 | $this->userId = isset( $config['user_id'] ) ? $config['user_id'] : ''; 112 | } 113 | 114 | /** 115 | * Debug the access token. 116 | * 117 | * @return Instagram response. 118 | */ 119 | public function debug() { 120 | $getParams = array( // parameters for our endpoint 121 | 'endpoint' => '/' . self::ENDPOINT_DEBUG, 122 | 'params' => array( 123 | Params::INPUT_TOKEN => $this->value 124 | ) 125 | ); 126 | 127 | // get request 128 | $response = $this->get( $getParams ); 129 | 130 | // return response 131 | return $response; 132 | } 133 | 134 | /** 135 | * Get access token from a code. 136 | * 137 | * @param string $code the code from the facebook redirect. 138 | * @param string $redirectUri uri the user gets sent to after logging in with facebook. 139 | * @return Instagram response. 140 | */ 141 | public function getAccessTokenFromCode( $code, $redirectUri ) { 142 | $getParams = array( // parameters for our endpoint 143 | 'endpoint' => '/' . self::ENDPOINT_TOKEN, 144 | 'params' => array( 145 | Params::CLIENT_ID => $this->appId, 146 | Params::CLIENT_SECRET => $this->appSecret, 147 | Params::REDIRECT_URI => $redirectUri, 148 | Params::CODE => $code 149 | ) 150 | ); 151 | 152 | // get request 153 | $response = $this->get( $getParams ); 154 | 155 | // set class vars from response data 156 | $this->setDataFromResponse( $response ); 157 | 158 | // return response 159 | return $response; 160 | } 161 | 162 | /** 163 | * Get a long lived access token. 164 | * 165 | * @param string $accessToken the access token to exchange for a long lived one. 166 | * @return Instagram response. 167 | */ 168 | public function getLongLivedAccessToken( $accessToken ) { 169 | $getParams = array( // parameters for our endpoint 170 | 'endpoint' => '/' . self::ENDPOINT_TOKEN, 171 | 'params' => array( 172 | Params::CLIENT_ID => $this->appId, 173 | Params::CLIENT_SECRET => $this->appSecret, 174 | Params::FB_EXCHANGE_TOKEN => $accessToken, 175 | Params::GRANT_TYPE => GrantTypes::FB_EXCHANGE_TOKEN, 176 | 177 | ) 178 | ); 179 | 180 | // get request 181 | $response = $this->get( $getParams ); 182 | 183 | // set class vars from response data 184 | $this->setDataFromResponse( $response ); 185 | 186 | // return response 187 | return $response; 188 | } 189 | 190 | /** 191 | * Get the permissions a user has for the access token. 192 | * 193 | * @return Instagram response. 194 | */ 195 | public function getPermissions() { 196 | $getParams = array( // parameters for our endpoint 197 | 'endpoint' => '/' . $this->userId. '/' . self::ENDPOINT_PERMISSIONS 198 | ); 199 | 200 | // get request 201 | $response = $this->get( $getParams ); 202 | 203 | // return response 204 | return $response; 205 | } 206 | 207 | /** 208 | * Check if the access token is long lived or not. 209 | * 210 | * @return boolean 211 | */ 212 | public function isLongLived() { 213 | // check if expires at meets long lived requirements 214 | return $this->expiresAt ? $this->expiresAt > time() + ( 60 * 60 * 2 ) : true; 215 | } 216 | 217 | /** 218 | * Revoke permissions for a users access token. 219 | * 220 | * @param string $permissionName name of the permission to revoke leave blank to revoke all permissions. 221 | * @return Instagram response. 222 | */ 223 | public function revokePermissions( $permissionName = '' ) { 224 | $deleteParams = array( // parameters for our endpoint 225 | 'endpoint' => '/' . $this->userId. '/' . self::ENDPOINT_PERMISSIONS . '/' . $permissionName 226 | ); 227 | 228 | // delete request 229 | $response = $this->delete( $deleteParams ); 230 | 231 | // return response 232 | return $response; 233 | } 234 | 235 | /** 236 | * Set class variables from the token response. 237 | * 238 | * @param array $response the response from the api call. 239 | * @return void 240 | */ 241 | public function setDataFromResponse( $response ) { 242 | if ( isset( $response['access_token'] ) ) { // we have an access token 243 | // set the value from the response 244 | $this->value = $response['access_token']; 245 | 246 | // set expires at if we have it in the response 247 | $this->expiresAt = isset( $response['expires_in'] ) ? time() + $response['expires_in'] : 0; 248 | } 249 | } 250 | } 251 | 252 | ?> -------------------------------------------------------------------------------- /src/Instagram/Comment/Comment.php: -------------------------------------------------------------------------------- 1 | commentId = $config['comment_id']; 64 | } 65 | 66 | /** 67 | * Get a comment. 68 | * 69 | * @param array $params params for the GET request. 70 | * @return Instagram response. 71 | */ 72 | public function getSelf( $params = array() ) { 73 | $getParams = array( // parameters for our endpoint 74 | 'endpoint' => '/' . $this->commentId, 75 | 'params' => $this->getParams( $params ) 76 | ); 77 | 78 | // ig get request 79 | $response = $this->get( $getParams ); 80 | 81 | // return response 82 | return $response; 83 | } 84 | 85 | /** 86 | * Get params for the request. 87 | * 88 | * @param array $params specific params for the request. 89 | * @return array of params for the request. 90 | */ 91 | public function getParams( $params = array() ) { 92 | if ( $params ) { // specific params have been requested 93 | return $params; 94 | } else { // get all params 95 | // get field params 96 | $params[Params::FIELDS] = Fields::getDefaultCommentFields() . ',' . 97 | Fields::REPLIES . '{' . 98 | Fields::getDefaultCommentFields() . 99 | '}' 100 | ; 101 | 102 | // return our params 103 | return $params; 104 | } 105 | } 106 | 107 | /** 108 | * Set hide parameter on a comment. 109 | * 110 | * @param boolean $hide show or hide the comment with true|false. 111 | * @return Instagram Response. 112 | */ 113 | public function setHide( $hide ) { 114 | $postParams = array( // parameters for our endpoint 115 | 'endpoint' => '/' . $this->commentId, 116 | 'params' => array( 117 | Params::HIDE => $hide 118 | ) 119 | ); 120 | 121 | // ig get request 122 | $response = $this->post( $postParams ); 123 | 124 | // return response 125 | return $response; 126 | } 127 | 128 | /** 129 | * Delete a comment. 130 | * 131 | * @return Instagram Response. 132 | */ 133 | public function remove() { 134 | $postParams = array( // parameters for our endpoint 135 | 'endpoint' => '/' . $this->commentId 136 | ); 137 | 138 | // ig get request 139 | $response = $this->delete( $postParams ); 140 | 141 | // return response 142 | return $response; 143 | } 144 | } 145 | 146 | ?> -------------------------------------------------------------------------------- /src/Instagram/Comment/Replies.php: -------------------------------------------------------------------------------- 1 | '/' . $this->commentId . '/' . self::ENDPOINT, 71 | 'params' => array( 72 | Params::MESSAGE => $message 73 | ) 74 | ); 75 | 76 | // ig get request 77 | $response = $this->post( $postParams ); 78 | 79 | // return response 80 | return $response; 81 | } 82 | 83 | /** 84 | * Get replies for a comment. 85 | * 86 | * @param array $paramsparams for the GET request. 87 | * @return Instagram response. 88 | */ 89 | public function getSelf( $params = array() ) { 90 | $getParams = array( // parameters for our endpoint 91 | 'endpoint' => '/' . $this->commentId . '/' . $this->endpoint, 92 | 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultCommentFields( false ) ) 93 | ); 94 | 95 | // ig get request 96 | $response = $this->get( $getParams ); 97 | 98 | // return response 99 | return $response; 100 | } 101 | } 102 | 103 | ?> -------------------------------------------------------------------------------- /src/Instagram/Container/Container.php: -------------------------------------------------------------------------------- 1 | containerId = $config['container_id']; 71 | } 72 | 73 | /** 74 | * Get the status of a container. 75 | * 76 | * @param array $params params for the GET request. 77 | * @return Instagram response. 78 | */ 79 | public function getSelf( $params = array() ) { 80 | $getParams = array( // parameters for our endpoint 81 | 'endpoint' => '/' . $this->containerId, 82 | 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) 83 | ); 84 | 85 | // ig get request 86 | $response = $this->get( $getParams ); 87 | 88 | // return response 89 | return $response; 90 | } 91 | } 92 | 93 | ?> -------------------------------------------------------------------------------- /src/Instagram/FacebookLogin/FacebookLogin.php: -------------------------------------------------------------------------------- 1 | appId = $config['app_id']; 72 | 73 | // set the application secret 74 | $this->appSecret = $config['app_secret']; 75 | } 76 | 77 | /** 78 | * Get the url for a user to prompt them with the login dialog. 79 | * 80 | * @param string $redirectUri uri the user gets sent to after logging in with facebook. 81 | * @param array $permissions array of the permissions you want to request from the user. 82 | * @param string $state this gets passed back from facebook in the redirect uri. 83 | * @return Instagram response. 84 | */ 85 | public function getLoginDialogUrl( $redirectUri, $permissions, $state = '' ) { 86 | $params = array( // params required to generate the login url 87 | Params::CLIENT_ID => $this->appId, 88 | Params::REDIRECT_URI => $redirectUri, 89 | Params::STATE => $state, 90 | Params::SCOPE => Params::commaImplodeArray( $permissions ), 91 | Params::RESPONSE_TYPE => ResponseTypes::CODE, 92 | ); 93 | 94 | // return the login dialog url 95 | return Request::BASE_AUTHORIZATION_URL . '/' . $this->graphVersion . '/' . self::ENDPOINT . '?' . http_build_query( $params );; 96 | } 97 | } 98 | 99 | ?> -------------------------------------------------------------------------------- /src/Instagram/Hashtag/Hashtag.php: -------------------------------------------------------------------------------- 1 | hashtagId = $config['hashtag_id']; 70 | } 71 | 72 | /** 73 | * Get info on a hashtag. 74 | * 75 | * @param array $params params for the GET request. 76 | * @return Instagram response. 77 | */ 78 | public function getSelf( $params = array() ) { 79 | $getParams = array( // parameters for our endpoint 80 | 'endpoint' => '/' . $this->hashtagId, 81 | 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) 82 | ); 83 | 84 | // ig get request 85 | $response = $this->get( $getParams ); 86 | 87 | // return response 88 | return $response; 89 | } 90 | } 91 | 92 | ?> -------------------------------------------------------------------------------- /src/Instagram/Hashtag/RecentMedia.php: -------------------------------------------------------------------------------- 1 | userId = $config['user_id']; 67 | } 68 | 69 | /** 70 | * Get info on a hashtag. 71 | * 72 | * @param array $params params for the GET request. 73 | * @return Instagram response. 74 | */ 75 | public function getSelf( $params = array() ) { 76 | $getParams = array( // parameters for our endpoint 77 | 'endpoint' => '/' . $this->hashtagId . '/' . self::ENDPOINT, 78 | 'params' => $this->getParams( $params ) 79 | ); 80 | 81 | // ig get request 82 | $response = $this->get( $getParams ); 83 | 84 | // return response 85 | return $response; 86 | } 87 | 88 | /** 89 | * Get params for the request. 90 | * 91 | * @param array $params Specific params for the request. 92 | * @return array of params for the request. 93 | */ 94 | public function getParams( $params = array() ) { 95 | if ( $params ) { // specific params have been requested 96 | return $params; 97 | } else { // get all params 98 | // get field params 99 | $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . 100 | Fields::CHILDREN . '{' . 101 | Fields::getDefaultMediaChildrenFields() . 102 | '}' 103 | ; 104 | 105 | // add on the since query param farthest back it can be set is 24 hours 106 | $params[Params::USER_ID] = $this->userId; 107 | 108 | // return our params 109 | return $params; 110 | } 111 | } 112 | } 113 | 114 | ?> -------------------------------------------------------------------------------- /src/Instagram/Hashtag/TopMedia.php: -------------------------------------------------------------------------------- 1 | userId = $config['user_id']; 67 | } 68 | 69 | /** 70 | * Get info on a hashtag. 71 | * 72 | * @param array $params Params for the GET request. 73 | * @return Instagram Response. 74 | */ 75 | public function getSelf( $params = array() ) { 76 | $getParams = array( // parameters for our endpoint 77 | 'endpoint' => '/' . $this->hashtagId . '/' . self::ENDPOINT, 78 | 'params' => $this->getParams( $params ) 79 | ); 80 | 81 | // ig get request 82 | $response = $this->get( $getParams ); 83 | 84 | // return response 85 | return $response; 86 | } 87 | 88 | /** 89 | * Get params for the request. 90 | * 91 | * @param array $params Specific params for the request. 92 | * @return array of params for the request. 93 | */ 94 | public function getParams( $params = array() ) { 95 | if ( $params ) { // specific params have been requested 96 | return $params; 97 | } else { // get all params 98 | // get field params 99 | $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . 100 | Fields::CHILDREN . '{' . 101 | Fields::getDefaultMediaChildrenFields() . 102 | '}' 103 | ; 104 | 105 | // add on the since query param farthest back it can be set is 24 hours 106 | $params[Params::USER_ID] = $this->userId; 107 | 108 | // return our params 109 | return $params; 110 | } 111 | } 112 | } 113 | 114 | ?> -------------------------------------------------------------------------------- /src/Instagram/HashtagSearch/HashtagSearch.php: -------------------------------------------------------------------------------- 1 | userId = $config['user_id']; 66 | } 67 | 68 | /** 69 | * Get info on a hashtag. 70 | * 71 | * @param string $hashtagName name of hashtag to get ID for. 72 | * @return Instagram response. 73 | */ 74 | public function getSelf( $hashtagName ) { 75 | $getParams = array( // parameters for our endpoint 76 | 'endpoint' => '/' . self::ENDPOINT, 77 | 'params' => array( 78 | Params::USER_ID => $this->userId, 79 | Params::Q => $hashtagName 80 | ) 81 | ); 82 | 83 | // ig get request 84 | $response = $this->get( $getParams ); 85 | 86 | // return response 87 | return $response; 88 | } 89 | } 90 | 91 | ?> -------------------------------------------------------------------------------- /src/Instagram/Instagram.php: -------------------------------------------------------------------------------- 1 | setAccessToken( isset( $config['access_token'] ) ? $config['access_token'] : '' ); 88 | 89 | // instantiate the client 90 | $this->client = new Curl(); 91 | 92 | // set graph version 93 | $this->graphVersion = isset( $config['graph_version'] ) ? $config['graph_version'] : self::DEFAULT_GRAPH_VERSION; 94 | } 95 | 96 | /** 97 | * Sends a GET request to Graph and returns the result. 98 | * 99 | * @param array $params params for the GET request. 100 | * @return Instagram response. 101 | */ 102 | public function get( $params ) { 103 | // check for params 104 | $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); 105 | 106 | // perform GET request 107 | return $this->sendRequest( Request::METHOD_GET, $params['endpoint'], $endpointParams ); 108 | } 109 | 110 | /** 111 | * Sends a POST request to Graph and returns the result. 112 | * 113 | * @param array $params params for the POST request. 114 | * @return Instagram response. 115 | */ 116 | public function post( $params ) { 117 | // check for params 118 | $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); 119 | 120 | // perform POST request 121 | return $this->sendRequest( Request::METHOD_POST, $params['endpoint'], $endpointParams ); 122 | } 123 | 124 | /** 125 | * Sends a DELETE request to Graph and returns the result. 126 | * 127 | * @param array $params params for the DELETE request. 128 | * @return Instagram response. 129 | */ 130 | public function delete( $params ) { 131 | // check for params 132 | $endpointParams = isset( $params['params'] ) ? $params['params'] : array(); 133 | 134 | // perform DELETE request 135 | return $this->sendRequest( Request::METHOD_DELETE, $params['endpoint'], $endpointParams ); 136 | } 137 | 138 | /** 139 | * Send a request to the Instagram Graph API and returns the result. 140 | * 141 | * @param string $method HTTP method. 142 | * @param string $endpoint endpoint for the request. 143 | * @param string $params parameters for the endpoint. 144 | * @return Instagram response. 145 | */ 146 | public function sendRequest( $method, $endpoint, $params ) { 147 | // create our request 148 | $this->request = new Request( $method, $endpoint, $params, $this->graphVersion, $this->accessToken ); 149 | 150 | // send the request to the client for processing 151 | $response = $this->client->send( $this->request ); 152 | 153 | // set prev and next links 154 | $this->setPrevNextLinks( $response ); 155 | 156 | // append the request to the response 157 | $response['debug'] = $this; 158 | 159 | // return the response 160 | return $response; 161 | } 162 | 163 | /** 164 | * Send a custom GET request to the Instagram Graph API and returns the result. 165 | * 166 | * @param string $customUrl the entire url for the request. 167 | * @return Instagram response. 168 | */ 169 | public function sendCustomRequest( $customUrl ) { 170 | // create our request 171 | $this->request = new Request( Request::METHOD_GET ); 172 | 173 | // set our custom url for the request 174 | $this->request->setUrl( $this->graphVersion, $customUrl ); 175 | 176 | // return the response 177 | $response = $this->client->send( $this->request ); 178 | 179 | // set prev and next links 180 | $this->setPrevNextLinks( $response ); 181 | 182 | // append the request to the response 183 | $response['debug'] = $this; 184 | 185 | // return the response 186 | return $response; 187 | } 188 | 189 | /** 190 | * Request previous or next page data. 191 | * 192 | * @param string $page specific page to request. 193 | * @return array of previous or next page data.. 194 | */ 195 | public function getPage( $page ) { 196 | // get the page to use 197 | $pageUrl = Params::NEXT == $page ? $this->pagingNextLink : $this->pagingPreviousLink; 198 | 199 | // return the response from the request 200 | return $this->sendCustomRequest( $pageUrl ); 201 | } 202 | 203 | /** 204 | * Set previous and next links from the response. 205 | * 206 | * @param array &$response response from the api. 207 | * @return void. 208 | */ 209 | public function setPrevNextLinks( &$response ) { 210 | // set paging next/previous links 211 | $this->pagingNextLink = $response['paging_next_link'] = isset( $response[Fields::PAGING][Params::NEXT] ) ? $response[Fields::PAGING][Params::NEXT] : ''; 212 | $this->pagingPreviousLink = $response['paging_previous_link'] = isset( $response[Fields::PAGING][Params::PREVIOUS] ) ? $response[Fields::PAGING][Params::PREVIOUS] : ''; 213 | } 214 | 215 | /** 216 | * Set the access token. 217 | * 218 | * @param string $accessToken set the access token. 219 | * @return void. 220 | */ 221 | public function setAccessToken( $accessToken ) { 222 | $this->accessToken = $accessToken; 223 | } 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 string $endpoint endpoint for the request. 231 | * @param array $params specific request params. 232 | * @return void 233 | */ 234 | public function calcLinkFromCursor( $type, &$response, $endpoint, $params ) { 235 | if ( isset( $response[Fields::PAGING][Fields::CURSORS][$type] ) ) { // we have paging 236 | // set the after cursor 237 | $params[$type] = $response[Fields::PAGING][Fields::CURSORS][$type]; 238 | 239 | // create our request 240 | $request = new Request( Request::METHOD_GET, $endpoint, $params, $this->graphVersion, $this->accessToken ); 241 | 242 | // set paging type based 243 | $pagingOrder = Params::AFTER == $type ? Params::NEXT : Params::PREVIOUS; 244 | 245 | // set paging next to the url for the next request 246 | $response[Fields::PAGING][$pagingOrder] = $request->getUrl(); 247 | } 248 | } 249 | } 250 | 251 | ?> -------------------------------------------------------------------------------- /src/Instagram/Media/Children.php: -------------------------------------------------------------------------------- 1 | '/' . $this->mediaId . '/' . self::ENDPOINT, 70 | 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultMediaChildrenFields( false ) ) 71 | ); 72 | 73 | // ig get request 74 | $response = $this->get( $getParams ); 75 | 76 | // return response 77 | return $response; 78 | } 79 | } 80 | 81 | ?> -------------------------------------------------------------------------------- /src/Instagram/Media/Comments.php: -------------------------------------------------------------------------------- 1 | '/' . $this->mediaId . '/' . self::ENDPOINT, 71 | 'params' => array( 72 | Params::MESSAGE => $message 73 | ) 74 | ); 75 | 76 | // ig get request 77 | $response = $this->post( $postParams ); 78 | 79 | // return response 80 | return $response; 81 | } 82 | 83 | /** 84 | * Get comments on a media post. 85 | * 86 | * @param array $params params for the GET request. 87 | * @return Instagram response. 88 | */ 89 | public function getSelf( $params = array() ) { 90 | $getParams = array( // parameters for our endpoint 91 | 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 92 | 'params' => $this->getParams( $params ) 93 | ); 94 | 95 | // ig get request 96 | $response = $this->get( $getParams ); 97 | 98 | // return response 99 | return $response; 100 | } 101 | 102 | /** 103 | * Get params for the request. 104 | * 105 | * @param array $params Specific params for the request. 106 | * @return array of params for the request. 107 | */ 108 | public function getParams( $params = array() ) { 109 | if ( $params ) { // specific params have been requested 110 | return $params; 111 | } else { // get all params 112 | // get field params 113 | $params[Params::FIELDS] = Fields::getDefaultCommentFields() . ',' . 114 | Fields::REPLIES . '{' . 115 | Fields::getDefaultCommentFields() . 116 | '}' 117 | ; 118 | 119 | // return our params 120 | return $params; 121 | } 122 | } 123 | } 124 | 125 | ?> -------------------------------------------------------------------------------- /src/Instagram/Media/Insights.php: -------------------------------------------------------------------------------- 1 | array( 61 | Metric::IMPRESSIONS, 62 | Metric::REACH, 63 | Metric::CAROUSEL_ALBUM_ENGAGEMENT, 64 | Metric::CAROUSEL_ALBUM_IMPRESSIONS, 65 | Metric::CAROUSEL_ALBUM_REACH, 66 | Metric::CAROUSEL_ALBUM_SAVED, 67 | Metric::CAROUSEL_ALBUM_VIDEO_VIEWS, 68 | Metric::ENGAGEMENT, 69 | Metric::VIDEO_VIEWS, 70 | Metric::SAVED 71 | ), 72 | Metric::MEDIA_TYPE_VIDEO => array( 73 | Metric::IMPRESSIONS, 74 | Metric::REACH, 75 | Metric::ENGAGEMENT, 76 | Metric::VIDEO_VIEWS, 77 | Metric::SAVED 78 | ), 79 | Metric::MEDIA_TYPE_STORY => array( 80 | Metric::IMPRESSIONS, 81 | Metric::REACH, 82 | Metric::EXITS, 83 | Metric::REPLIES, 84 | Metric::TAPS_FORWARD, 85 | Metric::TAPS_BACK 86 | ) 87 | ); 88 | 89 | /** 90 | * Contructor for instantiating a new object. 91 | * 92 | * @param array $config for the class. 93 | * @return void 94 | */ 95 | public function __construct( $config ) { 96 | // call parent for setup 97 | parent::__construct( $config ); 98 | 99 | // set media type so we know what metrics to call for 100 | $this->mediaType = strtolower( $config['media_type'] ); 101 | } 102 | 103 | /** 104 | * Get insights on a media post. 105 | * 106 | * @param array $params params for the GET request. 107 | * @return Instagram response. 108 | */ 109 | public function getSelf( $params = array() ) { 110 | $getParams = array( // parameters for our endpoint 111 | 'endpoint' => '/' . $this->mediaId . '/' . self::ENDPOINT, 112 | 'params' => $this->getParams( $params ) 113 | ); 114 | 115 | // ig get request 116 | $response = $this->get( $getParams ); 117 | 118 | // return response 119 | return $response; 120 | } 121 | 122 | /** 123 | * Get params for the request. 124 | * 125 | * @param array $params specific params for the request. 126 | * @return array of params for the request. 127 | */ 128 | public function getParams( $params = array() ) { 129 | if ( $params ) { // specific params have been requested 130 | return $params; 131 | } else { // get all params 132 | // set the metrics param 133 | $params[Params::METRIC] = Params::commaImplodeArray( $this->metrics[$this->mediaType] ); 134 | 135 | // return our params 136 | return $params; 137 | } 138 | } 139 | } 140 | 141 | ?> -------------------------------------------------------------------------------- /src/Instagram/Media/Media.php: -------------------------------------------------------------------------------- 1 | mediaId = $config['media_id']; 62 | } 63 | 64 | /** 65 | * Get info on a hashtag. 66 | * 67 | * @param array $params Params for the GET request. 68 | * @return Instagram Response. 69 | */ 70 | public function getSelf( $params = array() ) { 71 | $getParams = array( // parameters for our endpoint 72 | 'endpoint' => '/' . $this->mediaId, 73 | 'params' => $this->getParams( $params ) 74 | ); 75 | 76 | // ig get request 77 | $response = $this->get( $getParams ); 78 | 79 | // return response 80 | return $response; 81 | } 82 | 83 | /** 84 | * Set comments endabled for a media post. 85 | * 86 | * @param boolean $commentsEnabled enable or diable comments with true|false. 87 | * @return Instagram Response. 88 | */ 89 | public function setCommentsEnabled( $commentsEnabled ) { 90 | $postParams = array( // parameters for our endpoint 91 | 'endpoint' => '/' . $this->mediaId, 92 | 'params' => array( 93 | Params::COMMENT_ENABLED => $commentsEnabled 94 | ) 95 | ); 96 | 97 | // ig get request 98 | $response = $this->post( $postParams ); 99 | 100 | // return response 101 | return $response; 102 | } 103 | 104 | /** 105 | * Get params for the request. 106 | * 107 | * @param array $params specific params for the request. 108 | * @return array of params for the request. 109 | */ 110 | public function getParams( $params = array() ) { 111 | if ( $params ) { // specific params have been requested 112 | return $params; 113 | } else { // get all params 114 | // get field params 115 | $params[Params::FIELDS] = Fields::getDefaultMediaFieldsString(); 116 | 117 | // return our params 118 | return $params; 119 | } 120 | } 121 | } 122 | 123 | ?> -------------------------------------------------------------------------------- /src/Instagram/Page/Page.php: -------------------------------------------------------------------------------- 1 | pageId = $config['page_id']; 69 | } 70 | 71 | /** 72 | * Get the Instagram user connected to the Facebook page. 73 | * 74 | * @param array $params params for the GET request. 75 | * @return Instagram response. 76 | */ 77 | public function getSelf( $params = array() ) { 78 | $getParams = array( // parameters for our endpoint 79 | 'endpoint' => '/' . $this->pageId, 80 | 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) 81 | ); 82 | 83 | // ig get request 84 | $response = $this->get( $getParams ); 85 | 86 | // return response 87 | return $response; 88 | } 89 | } 90 | 91 | ?> -------------------------------------------------------------------------------- /src/Instagram/Request/Curl.php: -------------------------------------------------------------------------------- 1 | $request->getUrl(), 65 | CURLOPT_RETURNTRANSFER => true, // Return response as string 66 | CURLOPT_SSL_VERIFYHOST => 2, 67 | CURLOPT_SSL_VERIFYPEER => true, 68 | CURLOPT_CUSTOMREQUEST => $request->getMethod(), 69 | CURLOPT_CAINFO => __DIR__ . '/certs/cacert.pem', 70 | ); 71 | 72 | if ( $request->getMethod() == Request::METHOD_POST ) { // need to add on post fields 73 | $options[CURLOPT_POSTFIELDS] = $request->getUrlBody(); 74 | } 75 | 76 | // initialize curl 77 | $this->curl = curl_init(); 78 | 79 | // set the options 80 | curl_setopt_array( $this->curl, $options ); 81 | 82 | // send the request 83 | $this->rawResponse = curl_exec( $this->curl ); 84 | 85 | // close curl connection 86 | curl_close( $this->curl ); 87 | 88 | // return nice json decoded response 89 | return json_decode( $this->rawResponse, true ); 90 | } 91 | } 92 | 93 | ?> -------------------------------------------------------------------------------- /src/Instagram/Request/Fields.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/GrantTypes.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/MediaTypes.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/Metric.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/Params.php: -------------------------------------------------------------------------------- 1 | $commaImplode ? self::commaImplodeArray( $fields ) : $fields 88 | ); 89 | } 90 | 91 | /** 92 | * Turn array into a comma separated string. 93 | * 94 | * @param array $array elements to be comma separated. 95 | * @return string comma separated list of fields 96 | */ 97 | public static function commaImplodeArray( $array = array() ) { 98 | // imploded string on commas and return 99 | return implode( ',', $array ); 100 | } 101 | } 102 | 103 | ?> -------------------------------------------------------------------------------- /src/Instagram/Request/Period.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/Request.php: -------------------------------------------------------------------------------- 1 | method = strtoupper( $method ); 101 | 102 | // set endptoint 103 | $this->endpoint = $endpoint; 104 | 105 | // set any params 106 | $this->params = $params; 107 | 108 | // set access token 109 | $this->accessToken = $accessToken; 110 | 111 | // set url 112 | $this->setUrl( $graphVersion ); 113 | } 114 | 115 | /** 116 | * Set the full url for the request. 117 | * 118 | * @param string $graphVersion the graph version we are using. 119 | * @param string $customUrl custom url for the request. 120 | * @return void 121 | */ 122 | public function setUrl( $graphVersion, $customUrl = '' ) { 123 | // generate the full url 124 | $this->url = $customUrl ? $customUrl : self::BASE_GRAPH_URL . '/' . $graphVersion . $this->endpoint; 125 | 126 | if ( $this->getMethod() !== Request::METHOD_POST && !$customUrl ) { // not post or custom request so we have work to do 127 | // get the params 128 | $params = $this->getParams(); 129 | 130 | // build the query string and append to url 131 | $this->url .= '?' . http_build_query( $params ); 132 | } 133 | } 134 | 135 | /** 136 | * Returns the body of the request. 137 | * 138 | * @return string 139 | */ 140 | public function getUrlBody() { 141 | // get params 142 | $params = $this->getPostParams(); 143 | 144 | return http_build_query( $this->params ); 145 | } 146 | 147 | /** 148 | * Return the params for this request. 149 | * 150 | * @return array 151 | */ 152 | public function getParams() { 153 | if ( $this->accessToken ) { // append access token to params 154 | $this->params['access_token'] = $this->accessToken; 155 | } 156 | 157 | // return params array 158 | return $this->params; 159 | } 160 | 161 | /** 162 | * Return the HTTP method for this request. 163 | * 164 | * @return string 165 | */ 166 | public function getMethod() { 167 | return $this->method; 168 | } 169 | 170 | /** 171 | * Only return params on POST requests. 172 | * 173 | * @return array 174 | */ 175 | public function getPostParams() { 176 | if ( $this->getMethod() === 'POST' ) { // request is a post 177 | // return the array of params 178 | return $this->getParams(); 179 | } 180 | 181 | // return emtpy array 182 | return array(); 183 | } 184 | 185 | /** 186 | * Return the endpoint URL this request. 187 | * 188 | * @return string 189 | */ 190 | public function getUrl() { 191 | return $this->url; 192 | } 193 | } 194 | 195 | ?> -------------------------------------------------------------------------------- /src/Instagram/Request/ResponseTypes.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/Request/Scope.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Instagram/User/BusinessDiscovery.php: -------------------------------------------------------------------------------- 1 | username = $config['username']; 98 | } 99 | 100 | /** 101 | * Get the users account business discovery information and posts. 102 | * 103 | * @param array $params Params for the GET request. 104 | * @return Instagram Response. 105 | */ 106 | public function getSelf( $params = array() ) { 107 | $getParams = array( // parameters for our endpoint 108 | 'endpoint' => '/' . $this->userId, 109 | 'params' => $this->getParams( $params ) 110 | ); 111 | 112 | // ig get request 113 | $response = $this->get( $getParams ); 114 | 115 | // calculate the next link for paging 116 | $this->calcNextLink( $response ); 117 | 118 | // set prev and next links 119 | $this->setPrevNextLinks( $response ); 120 | 121 | // return response 122 | return $response; 123 | } 124 | 125 | /** 126 | * Calculate next link based on the cursors. 127 | * 128 | * @param array $response Instagram api response. 129 | * @return void 130 | */ 131 | public function calcNextLink( &$response ) { 132 | if ( isset( $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::BEFORE] ) ) { // we have previous page 133 | // get fields string 134 | $fieldsString = $this->getParams(); 135 | 136 | // calculate after string with cursor 137 | $snippet = Fields::MEDIA . '.' . Params::BEFORE . '(' . $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::BEFORE] . '){'; 138 | 139 | // update old fields with cursor 140 | $newFieldsParams = str_replace( Fields::MEDIA . '{', $snippet, $fieldsString ); 141 | 142 | // create our media endpoint 143 | $endpoint = '/' . $this->userId . '/'; 144 | 145 | // create our request 146 | $request = new Request( Request::METHOD_GET, $endpoint, $newFieldsParams, $this->graphVersion, $this->accessToken ); 147 | 148 | // set paging next to the url for the next request 149 | $response[Fields::PAGING][Params::PREVIOUS] = $request->getUrl(); 150 | } 151 | 152 | if ( isset( $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::AFTER] ) ) { // we have another page 153 | // get fields string 154 | $fieldsString = $this->getParams(); 155 | 156 | // calculate after string with cursor 157 | $snippet = Fields::MEDIA . '.' . Params::AFTER . '(' . $response[Fields::BUSINESS_DISCOVERY][Fields::MEDIA][Fields::PAGING][Fields::CURSORS][Params::AFTER] . '){'; 158 | 159 | // update old fields with cursor 160 | $newFieldsParams = str_replace( Fields::MEDIA . '{', $snippet, $fieldsString ); 161 | 162 | // create our media endpoint 163 | $endpoint = '/' . $this->userId . '/'; 164 | 165 | // create our request 166 | $request = new Request( Request::METHOD_GET, $endpoint, $newFieldsParams, $this->graphVersion, $this->accessToken ); 167 | 168 | // set paging next to the url for the next request 169 | $response[Fields::PAGING][Params::NEXT] = $request->getUrl(); 170 | } 171 | } 172 | 173 | /** 174 | * Request previous or next page data. 175 | * 176 | * @param string $page specific page to request. 177 | * @return array of previous or next page data.. 178 | */ 179 | public function getMediaPage( $page ) { 180 | // get the page to use 181 | $pageUrl = Params::NEXT == $page ? $this->pagingNextLink : $this->pagingPreviousLink; 182 | 183 | // return the response from the request 184 | $mediaPageRequest = $this->sendCustomRequest( $pageUrl ); 185 | 186 | // calculate the next link for paging 187 | $this->calcNextLink( $mediaPageRequest ); 188 | 189 | // set prev and next links 190 | $this->setPrevNextLinks( $mediaPageRequest ); 191 | 192 | return $mediaPageRequest; 193 | } 194 | 195 | /** 196 | * Get params for the request. 197 | * 198 | * @param array $params specific params for the request. 199 | * @return array of params for the request. 200 | */ 201 | public function getParams( $params = array() ) { 202 | if ( $params ) { // specific params have been requested 203 | return $params; 204 | } else { // get all params 205 | // create our fields string for business discovery 206 | $fieldsString = Fields::BUSINESS_DISCOVERY . '.' . Fields::USERNAME . '(' . $this->username . '){' . 207 | Params::commaImplodeArray( $this->fields ) . ',' . 208 | Fields::MEDIA . '{' . 209 | Params::commaImplodeArray( $this->mediaFields ) . ',' . 210 | Fields::CHILDREN . '{' . 211 | Fields::getDefaultMediaChildrenFields() . 212 | '}' . 213 | '}' . 214 | '}'; 215 | 216 | // return our params 217 | return Params::getFieldsParam( $fieldsString, false ); 218 | } 219 | } 220 | } 221 | 222 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/ContentPublishingLimit.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 78 | 'params' => $this->getParams( $params ) 79 | ); 80 | 81 | // ig get request 82 | $response = $this->get( $getParams ); 83 | 84 | // return response 85 | return $response; 86 | } 87 | 88 | /** 89 | * Get params for the request. 90 | * 91 | * @param array $params specific params for the request. 92 | * @return array of params for the request. 93 | */ 94 | public function getParams( $params = array() ) { 95 | if ( $params ) { // specific params have been requested 96 | return $params; 97 | } else { // get all params 98 | // get field params 99 | $params = Params::getFieldsParam( $this->fields ); 100 | 101 | // add on the since query param farthest back it can be set is 24 hours 102 | $params[Params::SINCE] = ( new \DateTime())->modify( '-23 hours' )->getTimestamp(); 103 | 104 | // return our params 105 | return $params; 106 | } 107 | } 108 | } 109 | 110 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/Insights.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 84 | 'params' => $this->getParams( $params ) 85 | ); 86 | 87 | // ig get request 88 | $response = $this->get( $getParams ); 89 | 90 | // return response 91 | return $response; 92 | } 93 | 94 | /** 95 | * Get params for the request. 96 | * 97 | * @param array $params specific params for the request. 98 | * @return array of params for the request. 99 | */ 100 | public function getParams( $params = array() ) { 101 | if ( $params ) { // specific params have been requested 102 | return $params; 103 | } else { // get all params 104 | // set the metrics param 105 | $params[Params::METRIC] = Params::commaImplodeArray( $this->metrics ); 106 | 107 | // set the period param 108 | $params[Params::PERIOD] = $this->period; 109 | 110 | // return our params 111 | return $params; 112 | } 113 | } 114 | } 115 | 116 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/LiveMedia.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 70 | 'params' => $params ? $params : Params::getFieldsParam( Fields::getDefaultMediaFields( false ) ) 71 | ); 72 | 73 | // ig get request 74 | $response = $this->get( $getParams ); 75 | 76 | // return response 77 | return $response; 78 | } 79 | } 80 | 81 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/Media.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 78 | 'params' => $params ? $params : array() 79 | ); 80 | 81 | if ( isset( $params[Params::CHILDREN] ) ) { // carousel container requires more children params 82 | $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::CAROUSEL; 83 | } elseif ( isset( $params[Params::VIDEO_URL] ) && !isset( $params[Params::MEDIA_TYPE] ) ) { // video container requires more params and to not overide in case REELS is passed 84 | $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::VIDEO; 85 | } elseif ( isset( $params[Params::VIDEO_URL] ) && isset( $params[Params::MEDIA_TYPE] ) ) { // set url and type to whatever is passed in 86 | $postParams['params'][Params::MEDIA_TYPE] = $params[Params::MEDIA_TYPE]; 87 | } elseif ( isset( $params[Params::IMAGE_URL] ) && isset( $params[Params::MEDIA_TYPE] ) ) { // set url and type to whatever is passed in 88 | $postParams['params'][Params::MEDIA_TYPE] = MediaTypes::STORIES; 89 | } 90 | 91 | // ig get request 92 | $response = $this->post( $postParams ); 93 | 94 | // return response 95 | return $response; 96 | } 97 | 98 | /** 99 | * Get the users media. 100 | * 101 | * @param array $params params for the GET request. 102 | * @return Instagram response. 103 | */ 104 | public function getSelf( $params = array() ) { 105 | $getParams = array( // parameters for our endpoint 106 | 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 107 | 'params' => $this->getParams( $params ), //$params ? $params : Params::getFieldsParam( $this->fields ) 108 | ); 109 | 110 | // ig get request 111 | $response = $this->get( $getParams ); 112 | 113 | // return response 114 | return $response; 115 | } 116 | 117 | /** 118 | * Get params for the request. 119 | * 120 | * @param array $params specific params for the request. 121 | * @return array of params for the request. 122 | */ 123 | public function getParams( $params = array() ) { 124 | if ( $params ) { // specific params have been requested 125 | return $params; 126 | } else { // get all params 127 | // get field params 128 | $params[Params::FIELDS] = Fields::getDefaultMediaFieldsString(); 129 | 130 | // return our params 131 | return $params; 132 | } 133 | } 134 | } 135 | 136 | ?> 137 | -------------------------------------------------------------------------------- /src/Instagram/User/MediaPublish.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 69 | 'params' => array( 70 | Params::CREATION_ID => $containerId 71 | ) 72 | ); 73 | 74 | // ig get request 75 | $response = $this->post( $postParams ); 76 | 77 | // return response 78 | return $response; 79 | } 80 | } 81 | 82 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/MentionedComment.php: -------------------------------------------------------------------------------- 1 | commentId = $config['comment_id']; 62 | } 63 | 64 | /** 65 | * Get comment user is mentioned in. 66 | * 67 | * @param array $params Params for the GET request. 68 | * @return Instagram Response. 69 | */ 70 | public function getSelf( $params = array() ) { 71 | $getParams = array( // parameters for our endpoint 72 | 'endpoint' => '/' . $this->userId . '/', 73 | 'params' => $this->getParams( $params ) 74 | ); 75 | 76 | // ig get request 77 | $response = $this->get( $getParams ); 78 | 79 | // return response 80 | return $response; 81 | } 82 | 83 | /** 84 | * Get params for the request. 85 | * 86 | * @param array $params specific params for the request. 87 | * @return array of params for the request. 88 | */ 89 | public function getParams( $params = array() ) { 90 | if ( $params ) { // specific params have been requested 91 | return $params; 92 | } else { // get all params 93 | // get field params 94 | $params[Params::FIELDS] = Fields::MENTIONED_COMMENT . '.' . Fields::COMMENT_ID . '(' . $this->commentId . '){' . 95 | Fields::getDefaultCommentFields() . ',' . 96 | Fields::REPLIES . '{' . 97 | Fields::getDefaultRepliesFields() . 98 | '}' . 99 | '}'; 100 | 101 | // return our params 102 | return $params; 103 | } 104 | } 105 | } 106 | 107 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/MentionedMedia.php: -------------------------------------------------------------------------------- 1 | mediaId = $config['media_id']; 62 | } 63 | 64 | /** 65 | * Get media the user is mentioned in. 66 | * 67 | * @param array $params Params for the GET request. 68 | * @return Instagram Response. 69 | */ 70 | public function getSelf( $params = array() ) { 71 | $getParams = array( // parameters for our endpoint 72 | 'endpoint' => '/' . $this->userId . '/', 73 | 'params' => $this->getParams( $params ) 74 | ); 75 | 76 | // ig get request 77 | $response = $this->get( $getParams ); 78 | 79 | // return response 80 | return $response; 81 | } 82 | 83 | /** 84 | * Get params for the request. 85 | * 86 | * @param array $params specific params for the request. 87 | * @return array of params for the request. 88 | */ 89 | public function getParams( $params = array() ) { 90 | if ( $params ) { // specific params have been requested 91 | return $params; 92 | } else { // get all params 93 | // get field params 94 | $params[Params::FIELDS] = Fields::MENTIONED_MEDIA . '.' . Fields::MEDIA_ID . '(' . $this->mediaId . '){' . 95 | Fields::getDefaultMediaFieldsString() . 96 | '}'; 97 | 98 | // return our params 99 | return $params; 100 | } 101 | } 102 | } 103 | 104 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/Mentions.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 69 | 'params' => $params 70 | ); 71 | 72 | // ig get request 73 | $response = $this->post( $postParams ); 74 | 75 | // return response 76 | return $response; 77 | } 78 | 79 | /** 80 | * Create a comment on a comment in which a user was mentioned. 81 | * 82 | * @param string $message comment to post. 83 | * @return Instagram response. 84 | */ 85 | public function replyToComment( $params ) { 86 | $postParams = array( // parameters for our endpoint 87 | 'endpoint' => '/' . $this->userId . '/' . self::ENDPOINT, 88 | 'params' => $params 89 | ); 90 | 91 | // ig get request 92 | $response = $this->post( $postParams ); 93 | 94 | // return response 95 | return $response; 96 | } 97 | } 98 | 99 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/RecentlySearchedHashtags.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 74 | 'params' => $this->getParams( $params ) 75 | ); 76 | 77 | // ig get request 78 | $response = $this->get( $getParams ); 79 | 80 | // return response 81 | return $response; 82 | } 83 | 84 | /** 85 | * Get params for the request. 86 | * 87 | * @param array $params specific params for the request. 88 | * @return array of params for the request. 89 | */ 90 | public function getParams( $params = array() ) { 91 | if ( $params ) { // specific params have been requested 92 | return $params; 93 | } else { // get all params 94 | // set the limit param to max 95 | $params[Params::LIMIT] = $this->maxReturnLimit; 96 | 97 | // return our params 98 | return $params; 99 | } 100 | } 101 | } 102 | 103 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/Stories.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT 68 | ); 69 | 70 | // ig get request 71 | $response = $this->get( $getParams ); 72 | 73 | // return response 74 | return $response; 75 | } 76 | } 77 | 78 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/Tags.php: -------------------------------------------------------------------------------- 1 | '/' . $this->userId . '/' . self::ENDPOINT, 86 | 'params' => $this->getParams( $params ) 87 | ); 88 | 89 | // ig get request 90 | $response = $this->get( $getParams ); 91 | 92 | // return response 93 | return $response; 94 | } 95 | 96 | /** 97 | * Get params for the request. 98 | * 99 | * @param array $params specific params for the request. 100 | * @return array of params for the request. 101 | */ 102 | public function getParams( $params = array() ) { 103 | if ( $params ) { // specific params have been requested 104 | return $params; 105 | } else { // get all params 106 | // get media fields for the tagged posts 107 | $params[Params::FIELDS] = Fields::getDefaultMediaFields() . ',' . 108 | Fields::CHILDREN . '{' . 109 | Fields::getDefaultMediaChildrenFields() . 110 | '}' 111 | ; 112 | 113 | // return our params 114 | return $params; 115 | } 116 | } 117 | } 118 | 119 | ?> -------------------------------------------------------------------------------- /src/Instagram/User/User.php: -------------------------------------------------------------------------------- 1 | userId = isset( $config['user_id'] ) ? $config['user_id'] : ''; 83 | } 84 | 85 | /** 86 | * Get the users info. 87 | * 88 | * @param array $params params for the GET request. 89 | * @return Instagram response. 90 | */ 91 | public function getSelf( $params = array() ) { 92 | $getParams = array( // parameters for our endpoint 93 | 'endpoint' => '/' . $this->userId, 94 | 'params' => $params ? $params : Params::getFieldsParam( $this->fields ) 95 | ); 96 | 97 | // ig get request 98 | $response = $this->get( $getParams ); 99 | 100 | // return response 101 | return $response; 102 | } 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 | } 131 | } 132 | 133 | ?> -------------------------------------------------------------------------------- /src/Instagram/autoload.php: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------