From cb48e0f16fec2d0ca6681d4c1ee809d0d932d9db Mon Sep 17 00:00:00 2001 From: jsanahuja Date: Thu, 25 Feb 2021 20:26:26 +0100 Subject: [PATCH] Fix CORS empty response issue --- jquery.instagramFeed.js | 7 +++++-- jquery.instagramFeed.min.js | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jquery.instagramFeed.js b/jquery.instagramFeed.js index 283264a..e2988e2 100644 --- a/jquery.instagramFeed.js +++ b/jquery.instagramFeed.js @@ -1,7 +1,7 @@ /*! * jquery.instagramFeed * - * @version 2.1.0 + * @version 2.1.1 * * https://github.com/jsanahuja/jquery.instagramFeed * @@ -125,7 +125,10 @@ } data = JSON.parse(data.substr(0, data.length - 1)); data = data.entry_data.ProfilePage || data.entry_data.TagPage; - return data[0].graphql.user || data[0].graphql.hashtag; + if(typeof data !== "undefined"){ + return data[0].graphql.user || data[0].graphql.hashtag; + } + return false; break; case "userid": if(typeof data.data.user !== "undefined"){ diff --git a/jquery.instagramFeed.min.js b/jquery.instagramFeed.min.js index 3da791a..6e9128e 100644 --- a/jquery.instagramFeed.min.js +++ b/jquery.instagramFeed.min.js @@ -1 +1 @@ -(function(a){function b(a){return a.replace(/[&<>"'`=\/]/g,function(a){return l[a]})}function c(a){return"undefined"!=typeof a.node.edge_media_to_caption.edges[0]&&"undefined"!=typeof a.node.edge_media_to_caption.edges[0].node&&"undefined"!=typeof a.node.edge_media_to_caption.edges[0].node.text&&null!==a.node.edge_media_to_caption.edges[0].node.text?a.node.edge_media_to_caption.edges[0].node.text:"undefined"!=typeof a.node.title&&null!==a.node.title&&0!=a.node.title.length?a.node.title:!("undefined"==typeof a.node.accessibility_caption||null===a.node.accessibility_caption||0==a.node.accessibility_caption.length)&&a.node.accessibility_caption}function d(a,b){var c=b||!1;if(!b&&0new Date().getTime()&&(c=!0)}if(c){var e=localStorage.getItem(a.cache_data_key);if(null!==e)return JSON.parse(e)}return!1}function e(a,b){var c=localStorage.getItem(a.cache_time_key),d=0!=a.cache_time&&(null===c||parseInt(c)+60000*a.cache_time>new Date().getTime());d&&(localStorage.setItem(a.cache_data_key,JSON.stringify(b)),localStorage.setItem(a.cache_time_key,new Date().getTime()))}function f(a,b){switch(a){case"username":case"tag":try{b=b.split("window._sharedData = ")[1].split("")[0]}catch(a){return!1}return b=JSON.parse(b.substr(0,b.length-1)),b=b.entry_data.ProfilePage||b.entry_data.TagPage,b[0].graphql.user||b[0].graphql.hashtag;break;case"userid":return"undefined"!=typeof b.data.user&&b.data.user;}}function g(b,c,d,h){a.get(b,function(a){data=f(c,a),!1===data?h(!1):h(data)}).fail(function(a){1",g+="\""+("tag"==d.type?e.name+"",g+="tag"==d.type?"

#"+d.tag+"

":"

@"+e.full_name+" (@"+d.username+")

","username"==d.type&&d.display_biography&&(g+="

"+e.biography+"

"),g+=""),d.display_gallery)if("undefined"!=typeof e.is_private&&!0===e.is_private)g+="

This profile is private

";else{var j="undefined"==typeof k[d.image_size]?k[640]:k[d.image_size],l=(e.edge_owner_to_timeline_media||e.edge_hashtag_to_media).edges,m=l.length>d.items?d.items:l.length;g+=""}if(d.display_igtv&&"undefined"!=typeof e.edge_felix_video_timeline){var s=e.edge_felix_video_timeline.edges,m=s.length>d.items?d.items:s.length;if(0";for(var n=0;n",g+="",g+=""}g+=""}}a(d.container).html(g)}var j={host:"https://www.instagram.com/",username:"",tag:"",user_id:"",container:"",display_profile:!0,display_biography:!0,display_gallery:!0,display_captions:!1,display_igtv:!1,max_tries:8,callback:null,styling:!0,items:8,items_per_row:4,margin:.5,image_size:640,lazy_load:!1,cache_time:360,on_error:console.error},k={150:0,240:1,320:2,480:3,640:4},l={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};a.instagramFeed=function(b){var c=a.fn.extend({},j,b);return""==c.username&&""==c.tag&&""==c.user_id?(c.on_error("Instagram Feed: Error, no username, tag or user_id defined.",1),!1):("undefined"!=typeof b.display_profile&&""!=c.user_id&&console.warn("Instagram Feed: 'display_profile' is not available using 'user_id' (GraphQL API)"),"undefined"!=typeof b.display_biography&&""!=c.user_id&&console.warn("Instagram Feed: 'display_biography' is not available using 'user_id' (GraphQL API)"),"undefined"!=typeof c.get_data&&console.warn("Instagram Feed: options.get_data is deprecated, options.callback is always called if defined"),null==c.callback&&""==c.container)?(c.on_error("Instagram Feed: Error, neither container found nor callback defined.",2),!1):(""==c.username?""==c.tag?(c.type="userid",c.id=c.user_id):(c.type="tag",c.id=c.tag):(c.type="username",c.id=c.username),c.cache_data_key="instagramFeed_"+c.type+"_"+c.id,c.cache_time_key=c.cache_data_key+"_time",h(c,function(a){""!=c.container&&i(c,a),null!=c.callback&&c.callback(a)}),!0)}})(jQuery); +(function(a){function b(a){return a.replace(/[&<>"'`=\/]/g,function(a){return l[a]})}function c(a){return"undefined"!=typeof a.node.edge_media_to_caption.edges[0]&&"undefined"!=typeof a.node.edge_media_to_caption.edges[0].node&&"undefined"!=typeof a.node.edge_media_to_caption.edges[0].node.text&&null!==a.node.edge_media_to_caption.edges[0].node.text?a.node.edge_media_to_caption.edges[0].node.text:"undefined"!=typeof a.node.title&&null!==a.node.title&&0!=a.node.title.length?a.node.title:!("undefined"==typeof a.node.accessibility_caption||null===a.node.accessibility_caption||0==a.node.accessibility_caption.length)&&a.node.accessibility_caption}function d(a,b){var c=b||!1;if(!b&&0new Date().getTime()&&(c=!0)}if(c){var e=localStorage.getItem(a.cache_data_key);if(null!==e)return JSON.parse(e)}return!1}function e(a,b){var c=localStorage.getItem(a.cache_time_key),d=0!=a.cache_time&&(null===c||parseInt(c)+60000*a.cache_time>new Date().getTime());d&&(localStorage.setItem(a.cache_data_key,JSON.stringify(b)),localStorage.setItem(a.cache_time_key,new Date().getTime()))}function f(a,b){switch(a){case"username":case"tag":try{b=b.split("window._sharedData = ")[1].split("")[0]}catch(a){return!1}return b=JSON.parse(b.substr(0,b.length-1)),b=b.entry_data.ProfilePage||b.entry_data.TagPage,"undefined"!=typeof b&&(b[0].graphql.user||b[0].graphql.hashtag);break;case"userid":return"undefined"!=typeof b.data.user&&b.data.user;}}function g(b,c,d,h){a.get(b,function(a){data=f(c,a),!1===data?h(!1):h(data)}).fail(function(a){1",g+="\""+("tag"==d.type?e.name+"",g+="tag"==d.type?"

#"+d.tag+"

":"

@"+e.full_name+" (@"+d.username+")

","username"==d.type&&d.display_biography&&(g+="

"+e.biography+"

"),g+=""),d.display_gallery)if("undefined"!=typeof e.is_private&&!0===e.is_private)g+="

This profile is private

";else{var j="undefined"==typeof k[d.image_size]?k[640]:k[d.image_size],l=(e.edge_owner_to_timeline_media||e.edge_hashtag_to_media).edges,m=l.length>d.items?d.items:l.length;g+=""}if(d.display_igtv&&"undefined"!=typeof e.edge_felix_video_timeline){var s=e.edge_felix_video_timeline.edges,m=s.length>d.items?d.items:s.length;if(0";for(var n=0;n",g+="",g+=""}g+=""}}a(d.container).html(g)}var j={host:"https://www.instagram.com/",username:"",tag:"",user_id:"",container:"",display_profile:!0,display_biography:!0,display_gallery:!0,display_captions:!1,display_igtv:!1,max_tries:8,callback:null,styling:!0,items:8,items_per_row:4,margin:.5,image_size:640,lazy_load:!1,cache_time:360,on_error:console.error},k={150:0,240:1,320:2,480:3,640:4},l={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};a.instagramFeed=function(b){var c=a.fn.extend({},j,b);return""==c.username&&""==c.tag&&""==c.user_id?(c.on_error("Instagram Feed: Error, no username, tag or user_id defined.",1),!1):("undefined"!=typeof b.display_profile&&""!=c.user_id&&console.warn("Instagram Feed: 'display_profile' is not available using 'user_id' (GraphQL API)"),"undefined"!=typeof b.display_biography&&""!=c.user_id&&console.warn("Instagram Feed: 'display_biography' is not available using 'user_id' (GraphQL API)"),"undefined"!=typeof c.get_data&&console.warn("Instagram Feed: options.get_data is deprecated, options.callback is always called if defined"),null==c.callback&&""==c.container)?(c.on_error("Instagram Feed: Error, neither container found nor callback defined.",2),!1):(""==c.username?""==c.tag?(c.type="userid",c.id=c.user_id):(c.type="tag",c.id=c.tag):(c.type="username",c.id=c.username),c.cache_data_key="instagramFeed_"+c.type+"_"+c.id,c.cache_time_key=c.cache_data_key+"_time",h(c,function(a){""!=c.container&&i(c,a),null!=c.callback&&c.callback(a)}),!0)}})(jQuery); diff --git a/package.json b/package.json index 10482f0..c432b2c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery.instagramFeed", "description": "Instagram Feed without access token. Not using the Instagram API", "homepage": "https://github.com/jsanahuja/jquery.instagramFeed", - "version": "2.1.0", + "version": "2.1.1", "keywords": [ "instagram", "feed",