forked from ianckc/CodeIgniter-Instagram-Library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
408 lines (284 loc) · 13.9 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
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_lang.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);
}
}