PageSourceSearch

https://yogahousebangkok.com/wp-content/plugins/wd-instagram-feed/js/wdi_instagram.js?ver=1.1.23

js yogahousebangkok.com collected 2026-10-09 04:19:59 UTC 44,292 bytes, 1,427 lines download raw bytes

1/**
2 * WDIInstagram is jQuery based plugin which handles communication
3 * with instagram API endpoints
4 *
5 * Plugin Version: 1.0.0
6 * Author: Melik Karapetyan
7 * License: GPLv2 or later
8 *
9 *
10 *
11 *
12 *
13 * Methods:
14 *    getSelfInfo = function( args ) : Get information about the owner of the access_token.
15 *    searchForUsersByName = function( username, args ) : Get a list of users matching the query.
16 *      searchForTagsByName = function(tagname, args) : Search for tags by name.
17 *      getTagRecentMedia = function(tagname, args) : Gets recent media based on tagname
18 *
19 */
20
21
22
23/**
24 * example of arg
25 * @type {Object}
26 */
27// var args = {
28//  access_tokens: ['227416602.145c5c2.302096fa9b3b4a8bbe0cee9341a6d7f5'],
29//  filters: [{
30//  where: 'getTagRecentMedia',
31//  what: function(r) {
32//    return r;
33//  },
34// }, {
35//  where: 'searchForUsersByName',
36//    what: 'bbb',
37//  }],
38// }
39
40
41/**
42 * WDIInstagram object constructor
43 * @param {Object} args
44 *
45 * @param {Array}           [args.access_tokens] [array of lavid instagram access tokens]
46 * @param {Array}           [args.filters] [array of object defining filters]
47 * @param {Object}          [args.filters[i] ] [ filter object which contain 'where' : 'what' pair ]
48 * @param {String}          [args.filters.filter[i].where] [name of function where filter must be applied]
49 * @param {String or Array} [args.filters.filter[i].what] [name of filtering function,
50 *                       if function is in global scope then it should be name of the funtion
51 *                         else if function in method of some object then it should be an array
52 *                                ['parent_object_name','filtering_function_name']]
53 */
54function WDIInstagram(args)
55{
56
57  this.access_tokens = [];
58  this.filters = [];
59  if (typeof args != 'undefined') {
60    if (typeof args.access_tokens != 'undefined') {
61      this.access_tokens = args.access_tokens;
62    }
63    if (typeof args.filters != 'undefined') {
64      this.filters = args.filters;
65    }
66  }
67
68
69  var _this = this;
70
71  /**
72   * Default object for handling status codes
73   * @type {Object}
74   */
75  this.statusCode = {
76    429: function ()
77    {
78      console.log(' 429: Too many requests. Try after one hour');
79    },
80  }
81
82  /**
83   * gets filter function defined for specific method
84   * this function is internal function and cannot be called outside of this object
85   *
86   * @param  {String} methodName   [name of WDIInstagram method]
87   * @return {Function}            [filtering function for {methodName}]
88   */
89  this.getFilter = function (methodName)
90  {
91    var filters = _this.filters;
92    if (typeof filters == "undefined") {
93      return false;
94    }
95
96    for (var i = 0; i < filters.length; i++) {
97      if (filters[i].where == methodName) {
98
99        if (typeof filters[i].what == 'object' && filters[i].what.length == 2) {
100          if (typeof window[filters[i].what[0]] != 'undefined') {
101            if (typeof window[filters[i].what[0]][filters[i].what[1]] == 'function') {
102              return window[filters[i].what[0]][filters[i].what[1]];
103            }
104          }
105        } else
106          if (typeof filters[i].what == 'string') {
107            if (typeof window[filters[i].what] == 'function') {
108              return window[filters[i].what];
109            }
110          } else
111            if (typeof filters[i].what == 'function') {
112              return filters[i].what;
113            } else {
114              return false;
115            }
116      }
117    }
118    return false;
119  }
120
121  function getAccessToken()
122  {
123    var access_tokens = _this.access_tokens,
124      index = parseInt(Math.random(0, 1) * access_tokens.length);
125    return access_tokens[index];
126  }
127
128  /**
129   * Adds access token to this.access_tokens array
130   * non string values are not allowed
131   * @param {String} token [Instagram API access token]
132   */
133  this.addToken = function (token)
134  {
135    if (typeof token == 'string') {
136      _this.access_tokens.push(token);
137    }
138  }
139
140  /**
141   * Gets recent media based on tagname
142   *
143   *
144   * @definition success_callback => which function to call in case of success
145   * @definition error_callback   => which function to call in case of error
146   * @definition media_count      => number of media to request
147   * @definition min_tag_id       => Return media before this min_tag_id.
148   * @definition max_tag_id       => Return media after this max_tag_id.
149   * @definition statusCode       => StatusCode object.
150   *
151   * @param tagname               =>  A valid tag name without a leading #. (eg. snowy, nofilter)
152   * @param args = {
153   *       success    :   'success_callback',
154   *       error    :   'error_callback',
155   *       statusCode : statusCode
156   *       count      :   'media_count',
157   *     min_tag_id :   'min_tag_id',
158   *     max_tag_id :   'max_tag_id',
159   *     args : arguments to be passed to filtering function
160   *  }
161   *
162   *
163   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
164   * or you can pass as callback function an anonymous function
165   *
166   *
167   * @return object of founded media
168   */
169  this.getTagRecentMedia = function (tagname, args)
170  {
171    var instagram = this,
172      noArgument = false,
173      successFlag = false,
174      statusCode = this.statusCode,
175      errorFlag = false,
176      argFlag = false,
177      filter = this.getFilter('getTagRecentMedia'),
178
179      baseUrl = 'https://api.instagram.com/v1/tags/' + tagname + '/media/recent?access_token=' 
179+ getAccessToken();
180
181
182    if (typeof args == 'undefined' || args.length === 0) {
183      noArgument = true;
184    } else {
185
186      if ('success' in args) {
187        successFlag = true;
188      }
189      if ('statusCode' in args) {
190        statusCode = args['statusCode'];
191      }
192      if ('error' in args) {
193        errorFlag = true;
194      }
195//
196      if ('args' in args) {
197        argFlag = true;
198      } else {
199        args.args = {};
200      }
201//
202      if ('count' in args) {
203        args['count'] = parseInt(args['count']);
204        if (!Number.isInteger(args['count']) || args['count'] <= 0) {
205          args.count = 33;
206        }
207      } else {
208        args.count = 33;
209      }
210
211      baseUrl += '&count=' + args.count;
212
213      if ('min_tag_id' in args) {
214        baseUrl += '&min_tag_id=' + args.min_tag_id;
215      }
216
217      if ('max_tag_id' in args) {
218        baseUrl += '&max_tag_id=' + args.max_tag_id;
219      }
220    }
221
222    jQuery.ajax({
223      type: 'POST',
224      url: baseUrl,
225      dataType: 'jsonp',
226      success: function (response)
227      {
228        if (typeof response["data"] === "undefined") response["data"] = [];
229
230        if (successFlag) {
231          if (typeof args.success == 'object' && args.success.length == 2) {
232            if (typeof window[args.success[0]] != 'undefined') {
233              if (typeof window[args.success[0]][args.success[1]] == 'function') {
234                if (filter) {
235                  response = filter(response, instagram.filterArguments, args.args);
236                }
237                window[args.success[0]][args.success[1]](response);
238              }
239            }
240
241          } else
242            if (typeof args.success == 'string') {
243              if (typeof window[args.success] == 'function') {
244                if (filter) {
245                  response = filter(response, instagram.filterArguments, args.args);
246                }
247                window[args.success](response);
248              }
249            } else
250              if (typeof args.success == 'function') {
251                if (filter) {
252                  response = filter(response, instagram.filterArguments, args.args);
253                }
254                args.success(response);
255              }
256        }
257      },
258      error: function (response)
259      {
260        if (errorFlag) {
261          if (typeof args['error'] == 'object' && args['error'].length == 2) {
262            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
263              window[args['error'][0]][args['error'][1]](response);
264            }
265          } else
266            if (typeof args['error'] == 'string') {
267              if (typeof window[args['error']] == 'function') {
268                window[args['error']](response);
269              }
270            } else
271              if (typeof args['error'] == 'function') {
272                args['error'](response);
273              }
274        }
275      },
276      statusCode: statusCode
277    });
278
279  }
280
281
282  /**
283   * Search for tags by name.
284   *
285   *
286   * @definition success_callback => which function to call in case of success
287   * @definition error_callback   => which function to call in case of error
288   * @definition statusCode       => StatusCode object.
289   *
290   * @param tagname               =>  A valid tag name without a leading #. (eg. snowy, nofilter)
291   * @param args = {
292   *       success: 'success_callback',
293   *       error:   'error_callback',
294   *       statusCode : statusCode,
295   *  }
296   *
297   *
298   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
299   * or you can pass as callback function an anonymous function
300   *
301   *
302   * @return object of founded media
303   */
304
305  this.searchForTagsByName = function (tagname, args)
306  {
307    var instagram = this,
308      noArgument = false,
309      successFlag = false,
310      statusCode = this.statusCode;
311    errorFlag = false;
312    filter = this.getFilter('searchForTagsByName');
313
314    if (typeof args == 'undefined' || args.length === 0) {
315      noArgument = true;
316    } else {
317      if ('success' in args) {
318        successFlag = true;
319      }
320      if ('error' in args) {
321        errorFlag = true;
322      }
323      if ('statusCode' in args) {
324        statusCode = args['statusCode'];
325      }
326    }
327
328
329    jQuery.ajax({
330      type: 'POST',
331      url: 'https://api.instagram.com/v1/tags/search?q=' + tagname + '&access_token=' 
331+ getAccessToken(),
332      dataType: 'jsonp',
333      success: function (response)
334      {
335        if (successFlag) {
336          if (typeof args.success == 'object' && args.success.length == 2) {
337            if (typeof window[args.success[0]] != 'undefined') {
338              if (typeof window[args.success[0]][args.success[1]] == 'function') {
339                if (filter) {
340                  response = filter(response, instagram.filterArguments);
341                }
342                window[args.success[0]][args.success[1]](response);
343              }
344            }
345          } else
346            if (typeof args.success == 'string') {
347              if (typeof window[args.success] == 'function') {
348                if (filter) {
349                  response = filter(response, instagram.filterArguments);
350                }
351                window[args.success](response);
352              }
353            } else
354              if (typeof args.success == 'function') {
355                if (filter) {
356                  response = filter(response, instagram.filterArguments);
357                }
358                args.success(response);
359              }
360        }
361      },
362      error: function (response)
363      {
364        if (errorFlag) {
365          if (typeof args['error'] == 'object' && args['error'].length == 2) {
366            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
367              window[args['error'][0]][args['error'][1]](response);
368            }
369          } else
370            if (typeof args['error'] == 'string') {
371              if (typeof window[args['error']] == 'function') {
372                window[args['error']](response);
373              }
374            } else
375              if (typeof args['error'] == 'function') {
376                args['error'](response);
377              }
378        }
379      },
380      statusCode: statusCode
381    });
382  }
383
384
385  /**
386   * Get a list of users matching the query.
387   *
388   *
389   * @definition success_callback => which function to call in case of success
390   * @definition error_callback   => which function to call in case of error
391   * @definition statusCode       => StatusCode object.
392   *
393   * @param username
394   * @param args = {
395   *       success: 'success_callback',
396   *       error:   'error_callback',
397   *       statusCode : statusCode
398   *  }
399   *
400   *
401   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
402   * or you can pass as callback function an anonymous function
403   *
404   *
405   * @return object of founded users
406   */
407  this.searchForUsersByName = function (username, args)
408  {
409    var instagram = this,
410      noArgument = false,
411      successFlag = false,
412      statusCode = this.statusCode,
413      errorFlag = false,
414      filter = this.getFilter('searchForUsersByName');
415
416    if (typeof args == 'undefined' || args.length === 0) {
417      noArgument = true;
418    } else {
419      if ('success' in args) {
420        successFlag = true;
421      }
422      if ('error' in args) {
423        errorFlag = true;
424      }
425      if ('statusCode' in args) {
426        statusCode = args['statusCode'];
427      }
428    }
429
430
431    jQuery.ajax({
432      type: 'POST',
433      dataType: 'jsonp',
434      url: 'https://api.instagram.com/v1/users/search?q=' + username + '&access_token=' 
434+ getAccessToken(),
435      success: function (response)
436      {
437        if (successFlag) {
438          if (typeof args.success == 'object' && args.success.length == 2) {
439            if (typeof window[args.success[0]] != 'undefined') {
440              if (typeof window[args.success[0]][args.success[1]] == 'function') {
441                if (filter) {
442                  response = filter(response, instagram.filterArguments);
443                }
444                response.args = args;
445                window[args.success[0]][args.success[1]](response);
446              }
447            }
448          } else
449            if (typeof args.success == 'string') {
450              if (typeof window[args.success] == 'function') {
451                if (filter) {
452                  response = filter(response, instagram.filterArguments);
453                }
454                response.args = args;
455                window[args.success](response);
456              }
457            } else
458              if (typeof args.success == 'function') {
459                if (filter) {
460                  response = filter(response, instagram.filterArguments);
461                }
462                response.args = args;
463                args.success(response);
464              }
465        }
466      },
467      error: function (response)
468      {
469        if (errorFlag) {
470          if (typeof args['error'] == 'object' && args['error'].length == 2) {
471            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
472              window[args['error'][0]][args['error'][1]](response);
473            }
474          } else
475            if (typeof args['error'] == 'string') {
476              if (typeof window[args['error']] == 'function') {
477                window[args['error']](response);
478              }
479            } else
480              if (typeof args['error'] == 'function') {
481                args['error'](response);
482              }
483        }
484      },
485      statusCode: this.statusCode
486
487    });
488  }
489
490
491  /**
492   * Get the list of recent media liked by the owner of the access_token.
493   *
494   *
495   * @definition success_callback => which function to call in case of success
496   * @definition error_callback   => which function to call in case of error
497   * @definition statusCode       => StatusCode object.
498   * @param args = {
499   *       success: 'success_callback',
500   *       error:   'error_callback',
501   *       statusCode : statusCode
502   *  }
503   *
504   *
505   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
506   * or you can pass as callback function an anonymous function
507   *
508   * @return object of founded media
509   */
510
511  this.getRecentLikedMedia = function (args)
512  {
513    var instagram = this,
514      noArgument = false,
515      successFlag = false,
516      statusCode = this.statusCode,
517      errorFlag = false,
518      filter = this.getFilter('getRecentLikedMedia'),
519      baseUrl = 'https://api.instagram.com/v1/users/self/media/liked?access_token=' 
519+ getAccessToken();
520
521    if (typeof args == 'undefined' || args.length === 0) {
522      noArgument = true;
523    } else {
524      if ('success' in args) {
525        successFlag = true;
526      }
527      if ('error' in args) {
528        errorFlag = true;
529      }
530      if ('statusCode' in args) {
531        statusCode = args['statusCode'];
532      }
533      if ('args' in args) {
534        argFlag = true;
535      } else {
536        args.args = {};
537      }
538
539      if ('count' in args) {
540        args['count'] = parseInt(args['count']);
541        if (!Number.isInteger(args['count']) || args['count'] <= 0) {
542          args.count = 20;
543        }
544      } else {
545        args.count = 20;
546      }
547
548      baseUrl += '&count=' + args.count;
549
550      if ('next_max_like_id' in args) {
551        baseUrl += '&next_max_like_id=' + args.next_max_like_id;
552      }
553
554
555    }
556
557
558    jQuery.ajax({
559      type: 'POST',
560      dataType: 'jsonp',
561      url: baseUrl,
562      success: function (response)
563      {
564        if (successFlag) {
565          if (typeof args.success == 'object' && args.success.length == 2) {
566            if (typeof window[args.success[0]] != 'undefined') {
567              if (typeof window[args.success[0]][args.success[1]] == 'function') {
568                if (filter) {
569                  response = filter(response, instagram.filterArguments, args.args);
570                }
571                window[args.success[0]][args.success[1]](response);
572              }
573            }
574          } else
575            if (typeof args.success == 'string') {
576              if (typeof window[args.success] == 'function') {
577                if (filter) {
578                  response = filter(response, instagram.filterArguments, args.args);
579                }
580                window[args.success](response);
581              }
582            } else
583              if (typeof args.success == 'function') {
584                if (filter) {
585                  response = filter(response, instagram.filterArguments, args.args);
586                }
587                args.success(response);
588              }
589        }
590      },
591      error: function (response)
592      {
593        if (errorFlag) {
594          if (typeof args['error'] == 'object' && args['error'].length == 2) {
595            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
596              window[args['error'][0]][args['error'][1]](response);
597            }
598          } else
599            if (typeof args['error'] == 'string') {
600              if (typeof window[args['error']] == 'function') {
601                window[args['error']](response);
602              }
603            } else
604              if (typeof args['error'] == 'function') {
605                args['error'](response);
606              }
607        }
608      },
609      statusCode: statusCode
610
611    });
612  }
613
614
615  /**
616   * Get the most recent media published by a user.
617   * This endpoint requires the public_content scope if the user-id is not the owner of the access_token.
618   *
619   *
620   * @definition success_callback => which function to call in case of success
621   * @definition error_callback   => which function to call in case of error
622   * @definition media_count      => number of media to request
623   * @definition min_id           => Return media before this min_id.
624   * @definition max_id           => Return media after this max_id.
625   * @definition statusCode       => StatusCode object.
626   *
627   * @param args = {
628   *       success : 'success_callback',
629   *       error   : 'error_callback',
630   *       statusCode : statusCode,
631   *       count   : 'media_count',
632   *       min_id  : 'min_id',
633   *     max_id  : 'max_id',
634   *     args: arguments to be passed to filtering function
635   *  }
636   *
637   *
638   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
639   * or you can pass as callback function an anonymous function
640   *
641   *
642   * @return object of founded media
643   */
644  this.getUserRecentMedia = function (user_id, args)
645  {
646    var instagram = this,
647      noArgument = false,
648      successFlag = false,
649      argFlag = false,
650    //internal default object for statusCode handling
651      statusCode = this.statusCode,
652      errorFlag = false,
653      filter = this.getFilter('getUserRecentMedia'),
654      baseUrl = 'https://api.instagram.com/v1/users/' + user_id + '/media/recent/?access_token=' 
654+ getAccessToken();
655
656
657    if (typeof args == 'undefined' || args.length === 0) {
658      noArgument = true;
659    } else {
660      if ('success' in args) {
661        successFlag = true;
662      }
663
664      if ('statusCode' in args) {
665        statusCode = args['statusCode'];
666      }
667
668      if ('args' in args) {
669        argFlag = true;
670      } else {
671        args.args = {};
672      }
673
674      if ('error' in args) {
675        errorFlag = true;
676      }
677
678      if ('count' in args) {
679        args['count'] = parseInt(args['count']);
680        if (!Number.isInteger(args['count']) || args['count'] <= 0) {
681          args.count = 33;
682        }
683      } else {
684        args.count = 33;
685      }
686
687      baseUrl += '&count=' + args.count;
688
689      if ('min_id' in args) {
690        baseUrl += '&min_id=' + args.min_id;
691      }
692
693      if ('max_id' in args) {
694        baseUrl += '&max_id=' + args.max_id;
695      }
696    }
697
698
699    jQuery.ajax({
700      type: 'POST',
701      dataType: 'jsonp',
702      url: baseUrl,
703      success: function (response)
704      {
705        if (typeof response["data"] === "undefined") response["data"] = [];
706
707        if (successFlag) {
708          if (typeof args.success == 'object' && args.success.length == 2) {
709            if (typeof window[args.success[0]] != 'undefined') {
710              if (typeof window[args.success[0]][args.success[1]] == 'function') {
711                if (filter) {
712                  response = filter(response, instagram.filterArguments, args.args);
713                }
714                window[args.success[0]][args.success[1]](response);
715              }
716            }
717          } else
718            if (typeof args.success == 'string') {
719              if (typeof window[args.success] == 'function') {
720                if (filter) {
721                  response = filter(response, instagram.filterArguments, args.args);
722                }
723                window[args.success](response);
724              }
725            } else
726              if (typeof args.success == 'function') {
727                if (filter) {
728                  response = filter(response, instagram.filterArguments, args.args);
729                }
730                args.success(response);
731              }
732        }
733      },
734      error: function (response)
735      {
736        if (errorFlag) {
737          if (typeof args['error'] == 'object' && args['error'].length == 2) {
738            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
739              window[args['error'][0]][args['error'][1]](response);
740            }
741          } else
742            if (typeof args['error'] == 'string') {
743              if (typeof window[args['error']] == 'function') {
744                window[args['error']](response);
745              }
746            } else
747              if (typeof args['error'] == 'function') {
748                args['error'](response);
749              }
750        }
751      },
752      statusCode: statusCode
753
754    });
755
756  }
757
758
759  /**
760   * Get the most recent media published by the owner of the access_token.
761   *
762   *
763   * @definition success_callback => which function to call in case of success
764   * @definition error_callback   => which function to call in case of error
765   * @definition media_count      => number of media to request
766   * @definition min_id           => Return media before this min_id.
767   * @definition max_id           => Return media after this max_id.
768   * @definition statusCode       => StatusCode object.
769   *
770   * @param args = {
771   *       success : 'success_callback',
772   *       error   : 'error_callback',
773   *       count   : 'media_count',
774   *       min_id  : 'min_id'
775   *     max_id  : 'max_id'
776   *     statusCode : statusCode
777   *
778   *  }
779   *
780   *
781   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
782   * or you can pass as callback function an anonymous function
783   *
784   *
785   * @return object of founded media
786   */
787  this.getSelfRecentMedia = function (args)
788  {
789    var instagram = this,
790      noArgument = false,
791      successFlag = false,
792      statusCode = this.statusCode;
793    errorFlag = false,
794      filter = this.getFilter('getSelfRecentMedia'),
795      baseUrl = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' 
795+ getAccessToken();
796
797    if (typeof args == 'undefined' || args.length === 0) {
798      noArgument = true;
799    } else {
800      if ('success' in args) {
801        successFlag = true;
802      }
803
804      if ('error' in args) {
805        errorFlag = true;
806      }
807
808      if ('statusCode' in args) {
809        statusCode = args['statusCode'];
810      }
811
812      if ('count' in args) {
813        args['count'] = parseInt(args['count']);
814        if (!Number.isInteger(args['count']) || args['count'] <= 0) {
815          args.count = 33;
816        }
817      } else {
818        args.count = 33;
819      }
820
821      baseUrl += '&count=' + args.count;
822
823      if ('min_id' in args) {
824        baseUrl += '&min_id=' + args.min_id;
825      }
826
827      if ('max_id' in args) {
828        baseUrl += '&max_id=' + args.max_id;
829      }
830    }
831
832    jQuery.ajax({
833      type: 'POST',
834      dataType: 'jsonp',
835      url: baseUrl,
836      success: function (response)
837      {
838        if (successFlag) {
839          if (typeof args.success == 'object' && args.success.length == 2) {
840            if (typeof window[args.success[0]] != 'undefined') {
841              if (typeof window[args.success[0]][args.success[1]] == 'function') {
842                if (filter) {
843                  response = filter(response, instagram.filterArguments);
844                }
845                window[args.success[0]][args.success[1]](response);
846              }
847            }
848          } else
849            if (typeof args.success == 'string') {
850              if (typeof window[args.success] == 'function') {
851                if (filter) {
852                  response = filter(response, instagram.filterArguments);
853                }
854                window[args.success](response);
855              }
856            } else
857              if (typeof args.success == 'function') {
858                if (filter) {
859                  response = filter(response, instagram.filterArguments);
860                }
861                args.success(response);
862              }
863        }
864      },
865      error: function (response)
866      {
867        if (errorFlag) {
868          if (typeof args['error'] == 'object' && args['error'].length == 2) {
869            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
870              window[args['error'][0]][args['error'][1]](response);
871            }
872          } else
873            if (typeof args['error'] == 'string') {
874              if (typeof window[args['error']] == 'function') {
875                window[args['error']](response);
876              }
877            } else
878              if (typeof args['error'] == 'function') {
879                args['error'](response);
880              }
881        }
882      },
883      statusCode: statusCode
884
885    });
886  }
887
888
889  /**
890   * Get information about a user.
891   * This endpoint requires the public_content scope if the user-id is not the owner of the access_token.
892   *
893   *
894   * @definition success_callback => which function to call in case of success
895   * @definition error_callback   => which function to call in case of error
896   * @definition statusCode       => StatusCode object.
897   *
898   * @param args = {
899   *       success : 'success_callback',
900   *       error   : 'error_callback'
901   *       statusCode : statusCode
902   *  }
903   *
904   *
905   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
906   * or you can pass as callback function an anonymous function
907   *
908   *
909   * @return object of founded info
910   */
911  this.getUserInfo = function (user_id, args)
912  {
913    var instagram = this,
914      noArgument = false,
915      successFlag = false,
916      statusCode = this.statusCode,
917      errorFlag = false,
918      filter = this.getFilter('getUserInfo');
919
920    if (typeof args == 'undefined' || args.length === 0) {
921      noArgument = true;
922    } else {
923      if ('success' in args) {
924        successFlag = true;
925      }
926
927      if ('error' in args) {
928        errorFlag = true;
929      }
930
931      if ('statusCode' in args) {
932        statusCode = args['statusCode'];
933      }
934    }
935    jQuery.ajax({
936      type: 'POST',
937      dataType: 'jsonp',
938      url: 'https://api.instagram.com/v1/users/' + user_id + '/?access_token=' 
938+ getAccessToken(),
939      success: function (response)
940      {
941        if (successFlag) {
942          if (typeof args.success == 'object' && args.success.length == 2) {
943            if (typeof window[args.success[0]] != 'undefined') {
944              if (typeof window[args.success[0]][args.success[1]] == 'function') {
945                if (filter) {
946                  response = filter(response, instagram.filterArguments);
947                }
948                window[args.success[0]][args.success[1]](response);
949              }
950            }
951          } else
952            if (typeof args.success == 'string') {
953              if (typeof window[args.success] == 'function') {
954                if (filter) {
955                  response = filter(response, instagram.filterArguments);
956                }
957                window[args.success](response);
958              }
959            } else
960              if (typeof args.success == 'function') {
961                if (filter) {
962                  response = filter(response, instagram.filterArguments);
963                }
964                args.success(response);
965              }
966        }
967      },
968      error: function (response)
969      {
970        if (errorFlag) {
971          if (typeof args['error'] == 'object' && args['error'].length == 2) {
972            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
973              window[args['error'][0]][args['error'][1]](response);
974            }
975          } else
976            if (typeof args['error'] == 'string') {
977              if (typeof window[args['error']] == 'function') {
978                window[args['error']](response);
979              }
980            } else
981              if (typeof args['error'] == 'function') {
982                args['error'](response);
983              }
984        }
985      },
986      statusCode: statusCode
987
988    });
989  }
990
991
992  /**
993   * Get information about the owner of the access_token.
994   *
995   *
996   * @definition success_callback => which function to call in case of success
997   * @definition error_callback   => which function to call in case of error
998   * @definition statusCode       => StatusCode object.
999   *
1000   * @param args = {
1001   *       success : 'success_callback',
1002   *       error   : 'error_callback'
1003   *       statusCode : statusCode
1004   *  }
1005   *
1006   *
1007   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
1008   * or you can pass as callback function an anonymous function
1009   *
1010   *
1011   * @return object of founded info
1012   */
1013  this.getSelfInfo = function (args)
1014  {
1015    var instagram = this,
1016      noArgument = false,
1017      successFlag = false,
1018      statusCode = this.statusCode,
1019      errorFlag = false,
1020      filter = this.getFilter('getSelfInfo');
1021    if (typeof args == 'undefined' || args.length === 0) {
1022      noArgument = true;
1023    } else {
1024      if ('success' in args) {
1025        successFlag = true;
1026      }
1027
1028      if ('error' in args) {
1029        errorFlag = true;
1030      }
1031
1032      if ('statusCode' in args) {
1033        statusCode = args['statusCode'];
1034      }
1035    }
1036    jQuery.ajax({
1037      type: 'POST',
1038      dataType: 'jsonp',
1039      url: 'https://api.instagram.com/v1/users/self/?access_token=' 
1039+ getAccessToken(),
1040      success: function (response)
1041      {
1042        if (successFlag) {
1043          if (typeof args.success == 'object' && args.success.length == 2) {
1044            if (typeof window[args.success[0]] != 'undefined') {
1045              if (typeof window[args.success[0]][args.success[1]] == 'function') {
1046                if (filter) {
1047                  response = filter(response, instagram.filterArguments);
1048                }
1049                window[args.success[0]][args.success[1]](response);
1050              }
1051            }
1052          } else
1053            if (typeof args.success == 'string') {
1054              if (typeof window[args.success] == 'function') {
1055                if (filter) {
1056                  response = filter(response, instagram.filterArguments);
1057                }
1058                window[args.success](response);
1059              }
1060            } else
1061              if (typeof args.success == 'function') {
1062                if (filter) {
1063                  response = filter(response, instagram.filterArguments);
1064                }
1065                args.success(response);
1066              }
1067        }
1068      },
1069      error: function (response)
1070      {
1071        if (errorFlag) {
1072          if (typeof args['error'] == 'object' && args['error'].length == 2) {
1073            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
1074              window[args['error'][0]][args['error'][1]](response);
1075            }
1076          } else
1077            if (typeof args['error'] == 'string') {
1078              if (typeof window[args['error']] == 'function') {
1079                window[args['error']](response);
1080              }
1081            } else
1082              if (typeof args['error'] == 'function') {
1083                args['error'](response);
1084              }
1085        }
1086      },
1087      statusCode: statusCode
1088
1089    });
1090  }
1091
1092
1093  /**
1094   * Get a list of recent comments on a media object.
1095   * The public_content permission scope is required to get comments for a media
1096   * that does not belong to the owner of the access_token.
1097   *
1098   * @media_id                    => id of the media which comments must be getted
1099   * @definition success_callback => which function to call in case of success
1100   * @definition error_callback   => which function to call in case of error
1101   * @definition statusCode       => StatusCode object.
1102   *
1103   * @param args = {
1104   *       success : 'success_callback',
1105   *       error   : 'error_callback'
1106   *       statusCode : statusCode
1107   *  }
1108   *
1109   *
1110   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
1111   * or you can pass as callback function an anonymous function
1112   *
1113   *
1114   * @return object of founded comments
1115   */
1116  this.getRecentMediaComments = function (media_id, args)
1117  {
1118    var instagram = this,
1119      noArgument = false,
1120      successFlag = false,
1121      statusCode = this.statusCode,
1122      errorFlag = false,
1123      filter = this.getFilter('getRecentMediaComments');
1124    if (typeof args == 'undefined' || args.length === 0) {
1125      noArgument = true;
1126    } else {
1127      if ('success' in args) {
1128        successFlag = true;
1129      }
1130
1131      if ('error' in args) {
1132        errorFlag = true;
1133      }
1134
1135      if ('statusCode' in args) {
1136        statusCode = args['statusCode'];
1137      }
1138    }
1139    jQuery.ajax({
1140      type: 'POST',
1141      dataType: 'jsonp',
1142      url: 'https://api.instagram.com/v1/media/' + media_id + '/comments?access_token=' 
1142+ getAccessToken(),
1143      success: function (response)
1144      {
1145        if (successFlag) {
1146          if (typeof args.success == 'object' && args.success.length == 2) {
1147            if (typeof window[args.success[0]] != 'undefined') {
1148              if (typeof window[args.success[0]][args.success[1]] == 'function') {
1149                if (filter) {
1150                  response = filter(response, instagram.filterArguments);
1151                }
1152                window[args.success[0]][args.success[1]](response);
1153              }
1154            }
1155          } else
1156            if (typeof args.success == 'string') {
1157              if (typeof window[args.success] == 'function') {
1158                if (filter) {
1159                  response = filter(response, instagram.filterArguments);
1160                }
1161                window[args.success](response);
1162              }
1163            } else
1164              if (typeof args.success == 'function') {
1165                if (filter) {
1166                  response = filter(response, instagram.filterArguments);
1167                }
1168                args.success(response);
1169              }
1170        }
1171      },
1172      error: function (response)
1173      {
1174        if (errorFlag) {
1175          if (typeof args['error'] == 'object' && args['error'].length == 2) {
1176            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
1177              window[args['error'][0]][args['error'][1]](response);
1178            }
1179          } else
1180            if (typeof args['error'] == 'string') {
1181              if (typeof window[args['error']] == 'function') {
1182                window[args['error']](response);
1183              }
1184            } else
1185              if (typeof args['error'] == 'function') {
1186                args['error'](response);
1187              }
1188        }
1189      },
1190      statusCode: statusCode
1191
1192    });
1193  }
1194
1195
1196  /**
1197   * Get a list of users who have liked this media.
1198   *
1199   * @media_id                    => id of the media which comments must be getted
1200   * @definition success_callback => which function to call in case of success
1201   * @definition error_callback   => which function to call in case of error
1202   * @definition statusCode       => StatusCode object.
1203   *
1204   * @param args = {
1205   *       success : 'success_callback',
1206   *       error   : 'error_callback'
1207   *       statusCode : statusCode
1208   *  }
1209   *
1210   *
1211   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
1212   * or you can pass as callback function an anonymous function
1213   *
1214   *
1215   * @return object of founded comments
1216   */
1217  this.getRecentMediaLikes = function (media_id, args)
1218  {
1219    var instagram = this,
1220      noArgument = false,
1221      successFlag = false,
1222      statusCode = this.statusCode,
1223      errorFlag = false,
1224      filter = this.getFilter('getRecentMediaLikes');
1225
1226    if (typeof args == 'undefined' || args.length === 0) {
1227      noArgument = true;
1228    } else {
1229      if ('success' in args) {
1230        successFlag = true;
1231      }
1232
1233      if ('error' in args) {
1234        errorFlag = true;
1235      }
1236
1237      if ('statusCode' in args) {
1238        statusCode = args['statusCode'];
1239      }
1240    }
1241    jQuery.ajax({
1242      type: 'POST',
1243      dataType: 'jsonp',
1244      url: 'https://api.instagram.com/v1/media/' + media_id + '/likes?access_token=' 
1244+ getAccessToken(),
1245      success: function (response)
1246      {
1247        if (successFlag) {
1248          if (typeof args.success == 'object' && args.success.length == 2) {
1249            if (typeof window[args.success[0]] != 'undefined') {
1250              if (typeof window[args.success[0]][args.success[1]] == 'function') {
1251                if (filter) {
1252                  response = filter(response, instagram.filterArguments);
1253                }
1254                window[args.success[0]][args.success[1]](response);
1255              }
1256            }
1257          } else
1258            if (typeof args.success == 'string') {
1259              if (typeof window[args.success] == 'function') {
1260                if (filter) {
1261                  response = filter(response, instagram.filterArguments);
1262                }
1263                window[args.success](response);
1264              }
1265            } else
1266              if (typeof args.success == 'function') {
1267                if (filter) {
1268                  response = filter(response, instagram.filterArguments);
1269                }
1270                args.success(response);
1271              }
1272        }
1273      },
1274      error: function (response)
1275      {
1276        if (errorFlag) {
1277          if (typeof args['error'] == 'object' && args['error'].length == 2) {
1278            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
1279              window[args['error'][0]][args['error'][1]](response);
1280            }
1281          } else
1282            if (typeof args['error'] == 'string') {
1283              if (typeof window[args['error']] == 'function') {
1284                window[args['error']](response);
1285              }
1286            } else
1287              if (typeof args['error'] == 'function') {
1288                args['error'](response);
1289              }
1290        }
1291      },
1292      statusCode: statusCode
1293
1294    });
1295  }
1296
1297
1298  /**
1299   * make an ajax request based on url
1300   *
1301   *
1302   * @definition success_callback => which function to call in case of success
1303   * @definition error_callback   => which function to call in case of error
1304   * @definition statusCode       => StatusCode object.
1305   *
1306   * @param args = {
1307   *       success : 'success_callback',
1308   *       error   : 'error_callback',
1309   *       statusCode : statusCode,
1310   *       args.args : arguments to be passed to filter function
1311   *  }
1312   *
1313   *
1314   * if callback function is property of any other object just give it as array [ 'parent_object', 'callback_function']
1315   * or you can pass as callback function an anonymous function
1316   *
1317   *
1318   * @return object of founded media
1319   */
1320  this.requestByUrl = function (requestUrl, args)
1321  {
1322    var instagram = this,
1323      noArgument = false,
1324      successFlag = false,
1325      errorFlag = false,
1326      argFlag = false,
1327      statusCode = this.statusCode,
1328      filter = this.getFilter('requestByUrl'),
1329      urlParts,
1330      urlPart;
1331
1332    //changing access token to random one
1333    urlParts = requestUrl.split('?')[1].split('&');
1334    for (var i = 0; i < urlParts.length; i++) {
1335      urlParts[i] = urlParts[i].split('=');
1336      if (urlParts[i][0] == 'access_token') {
1337        urlParts[i][1] = getAccessToken();
1338      }
1339      urlParts[i] = urlParts[i].join('=');
1340    }
1341    urlParts = urlParts.join('&');
1342    requestUrl = requestUrl.split('?')[0] + '?' + urlParts;
1343
1344
1345    if (typeof args == 'undefined' || args.length === 0) {
1346      noArgument = true;
1347    } else {
1348      if ('success' in args) {
1349        successFlag = true;
1350      }
1351
1352      if ('args' in args) {
1353        argFlag = true;
1354      } else {
1355        args.args = {};
1356      }
1357
1358
1359      if ('error' in args) {
1360        errorFlag = true;
1361      }
1362
1363      if ('statusCode' in args) {
1364        statusCode = args['statusCode'];
1365      }
1366    }
1367
1368
1369    jQuery.ajax({
1370      type: 'POST',
1371      dataType: 'jsonp',
1372      url: requestUrl,
1373      success: function (response)
1374      {
1375        if (successFlag) {
1376          if (typeof args.success == 'object' && args.success.length == 2) {
1377            if (typeof window[args.success[0]] != 'undefined') {
1378              if (typeof window[args.success[0]][args.success[1]] == 'function') {
1379                if (filter) {
1380                  response = filter(response, instagram.filterArguments, args.args);
1381                }
1382                window[args.success[0]][args.success[1]](response);
1383              }
1384            }
1385          } else
1386            if (typeof args.success == 'string') {
1387              if (typeof window[args.success] == 'function') {
1388                if (filter) {
1389                  response = filter(response, instagram.filterArguments, args.args);
1390                }
1391                window[args.success](response);
1392              }
1393            } else
1394              if (typeof args.success == 'function') {
1395                if (filter) {
1396                  response = filter(response, instagram.filterArguments, args.args);
1397                }
1398                args.success(response);
1399              }
1400        }
1401      },
1402      error: function (response)
1403      {
1404        if (errorFlag) {
1405          if (typeof args['error'] == 'object' && args['error'].length == 2) {
1406            if (typeof window[args['error'][0]][args['error'][1]] == 'function') {
1407              window[args['error'][0]][args['error'][1]](response);
1408            }
1409          } else
1410            if (typeof args['error'] == 'string') {
1411              if (typeof window[args['error']] == 'function') {
1412                window[args['error']](response);
1413              }
1414            } else
1415              if (typeof args['error'] == 'function') {
1416                args['error'](response);
1417              }
1418        }
1419      },
1420      statusCode: statusCode
1421
1422    });
1423
1424  }
1425}
1426
1427

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.