Code Monkey home page Code Monkey logo

kasperlegarth / instastory.js Goto Github PK

View Code? Open in Web Editor NEW
35.0 2.0 14.0 63 KB

This is a jQuery plugin to make it easy to get a feed from instagram. No need of access tokens and other stuff, Only thing needed is jQuery.

Home Page: https://kasperlegarth.github.io/instastory.js/

License: MIT License

JavaScript 65.71% HTML 34.29%
jquery jquery-plugin instagram-feed instagram-scraper javascript instagram-photos hashtag-scraper hashtags userfeed hashtag

instastory.js's Introduction

Deprecated

As of Q1 2021, facebook made some changes to the instagram api that blocked the usage of this plugin.

instastory.js

This is a jQuery plugin to make it easier for developers to implement instagram feeds on websites. There is no need for access tokens and stuff like that. Use good old jQuery.

Table of contents

Getting startet

It is really simple to use the plugin all you need to to is include jQuery and the instastory.js file where you include your other scrips in the project.

<script src="jquery.min.js"></script>
<script src="path/to/script/instastory.js"></script>

Then the only thing left is to call the plugin on the DOM element that should be the container, call it with a hashtag that you want the history from.

$("#container").instastory("#coding");

As default the above line will give you the 6 most recent posts with the hashtag "coding" and will output the following html into the container element:

<a href="https://www.instagram.com/p/[POST URL]">
    <img src="[150x150 Image URL]" alt="[POST ACCESSIBILITY CAPTION]">
</a>

For more information about limit, image sizes etc. see options.

Options

If you are not the happy with the default options you can overwite some of the options either when you call the plugin or make an object that you feed the call with.

Directly on plugin call.

$("#container").instastory({
    get: "#coding",
    limit: 9
});

By using an object.

let options = {
    get: "#coding",
    limit: 9
};

$("#container").instastory(options);

Default options

Here is the full list of options and their default value.

Option Type Default Description
after function empty function You can parse a function to be executed after the plugin generates the html.
get string "" Define wath hashtag or username to get the images from. Remember to include either "#" or "@" This is the only option that is required to make it work. If nothing is defined as the get parameter, the plugin will return false.
imageSize int|string 150 Define what size you want the plugin to return the images in. Instagram provide images (thumbnails) in the following sizes: 150, 240, 320, 480, 640. You can also get the raw image by defining "raw"as you image size. The raw image size have the original dimensions (not a sqaure) If the you specify a size that isn't reconized it will return 150.
limit int 6 Define how many images you want the plugin to return. The max limit for an user feed is: 12 and the max limit for a hashtag feed is: 70 if limit is higher than descriped it will return the max limit
link boolean true Define if you want the images to be wrapped in links to the post.
template string "" Define a custom template for the plugin to use when rendering the html for the feed. This is also create for custom styling. For more info see the templating section

Templating

When using the plugin you have the option to define a string of html to be used by the plugin when it is rendering your feed to the page. Simple example looks like this:

options: {
    get: '#dog',
    template: '<img src="{{image}}" alt="{{caption}}">'
}

Here is a full list of tags to be used in the template:

Tag Description
{{accessibility_caption}} Returns the accessibility caption of the image. Great for alt tags, but be aware this it is not always possible for instagram to figure this out and then it returns: "No photo description available."
{{caption}} Returns the caption that the user uploaded with the image.
{{comments}} Returns the comment count of the image.
{{image}} Returns the image url in the desired image size.
{{likes}} Returns the number of people that have liked the image.
{{link}} Returns the url for the post (not the same as the image url)

Data Mode

This plugin only uses a fraction of all the information returned by the ajax call. You might want to do things differently than this plugin. Therefore if you call the plugin without a selector, you can get the raw data from the ajax call. Please note that this function may course the site to "hang" becouse the call is not async.

Simply do like this:

const rawData = $.instastory('@instagram');
console.log(rawData);

License

This project is licensed under the MIT Liense - see the LICENCE.md

Special thanks

It's dangerous to go alone. So here are a list of people whom have helped along the way:

instastory.js's People

Contributors

elemis avatar kasperlegarth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

instastory.js's Issues

DOM element

Just noticed a warning that says:
The DOM element you tried to initiate the plugin on, does not exist
This happens if there are more than one scripts for different feeds but only one of them (or none) is called on a page. How to initiate the script only if the element is present?
Link for demonstration: http://themes.iki-bir.com/inst/

The plugin is throwing an error

Hi there,

For some reason, the plugin is throwing this error:

Uncaught TypeError: data.graphql is undefined

This occurred today. I wonder if Instagram has stopped supporting graphql query?

instastory_error

Callback functions

Just wondering if you're planning to add before / after callback functions?

User and Hashtag getting error of undefined

Was working fine and now it will not work with @ or # and getting

Uncaught TypeError: Cannot read property 'hashtag' of undefined
at Object. (instastory.js:159)
at u (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest. (jquery.min.js:2)

Uncaught TypeError: Cannot read property 'user' of undefined
at Object. (instastory.js:159)
at u (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest. (jquery.min.js:2)

getting errors on demo site as well. https://kasperlegarth.github.io/instastory.js/

Stopped working with undefined error

The feeds suddenly stopped working returning the error:
TypeError: undefined is not an object (evaluating 'e.graphql[o.type]')
Screen Shot 2020-06-05 at 16 00 55
Seeing the same error on the official demo too and the user based feed doesn't work there as well. What might be the reason?

Cross=Origin Request Blocked

Hi there again,

I'm getting this error when I invoke a second Instagram account. If it's just one account, no problemo. But if I try to get the feed on another account, I get this error.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.instagram.com/berwickcycles/?__a=1. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

cors_error

Another error

On a certain internet connection, I see an error for line 143, saying:

Uncaught TypeError: Cannot read property 'user' of undefined
    at Object.success (instastory.js:143)
    at u (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at k (jquery.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery.min.js:2)

Line 143:
$container.html(generateHtml(data.graphql[settings.type]));

Please check http://themes.iki-bir.com/instastory/ for demonstration.

Is there a way to fix this issue?

Get combined @ and #

Hi there, is it possible in the 'get' option to conbine @ and #? For example, if I wanted to retrieve posts from @myUser, but only those tagged with @myhashtag?

Thanks!

Issue with images without caption

If no captions are available, the script returns an error for line 85 saying:

TypeError: undefined is not an object (evaluating 'post.edge_media_to_caption.edges[0].node')

line 85:
"{{caption}}": post.edge_media_to_caption.edges[0].node.text,

Please check http://themes.iki-bir.com/instastory/ for demonstration.

Is there a way to fix this issue?

Can't get templating to work

The plugin works fine if I use:

$("#container").instastory({
    get: "@nm_asian_family_center",
    limit: 9
});

or even using an object without a template, such as:

let options = {
 get: "@nm_asian_family_center",
 limit: 9,
};

$("#insta-container-footer").instastory(options);

However, as soon as I add in a template and inspect the result in devtools I see elements with:
<img src=(unknown) alt="">

Here is my example with a template:

let options = {
   get: "@nm_asian_family_center",
   limit: 9,
   template: '<img src="{{image}}" alt="">',
};
$("#insta-container-footer").instastory(options);

Any idea what I'm doing wrong? Thanks for any help!

edit
noticed that other tags in the template such as {{link}} are returning blank info as well.

Final Edit
I'm going to close this, I'm really dumb, and forgot that django will try and render the {{}} used in your plugin. Even more sad is that it took me having to go over all your code until the allReplace function till I realized my mistake. Thanks for the great plugin, everything is working fine now!

Inconsistent results

I am getting inconsistent results using this plugin. At times, it works fine, then at other times, I get the following error in the console: Uncaught TypeError: e.graphql is undefined.

I am using this plugin with the Missio theme.

Any suggestions?

Uncaught TypeError: data.graphql is undefined

I'm using Instastory pretty much "as is".
The instastory.js file is unaltered and all I'm using is:

$(document).ready(function() {
    $("#instastory-output").instastory({
        get: "#MY HASHTAG",
        limit: 68
    });
});

I uploaded it yesterday and it worked as a charm but today it doesn't work. I originally had limit set to 70 but changed it to 68 to get the rows of images filled up nicely.


Uncaught TypeError: data.graphql is undefined
    instastory https://MY URL/javascript/instastory.js:159
    jQuery 6
        j
        fireWith
        x
        b
        send
        ajax
    instastory https://MY URL/javascript/instastory.js:156
    <anonymous> https://MY URL/javascript/site.js?v=29:4
    jQuery 11
        j
        fireWith
        ready
        K
        promise
        ready
        init
        n
        <anonymous>
        <anonymous>
        <anonymous>

Uncaught TypeError: Cannot read property 'hashtag' of undefined

Hi,

Thanks for your library for 'instagram'.

Today I tried to get hash tag images from your library but the error occurred.

Uncaught TypeError: Cannot read property 'hashtag' of undefined
    at Object.<anonymous> (instastory.js:159)
    at u (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at k (jquery.min.js:2)
    at XMLHttpRequest.<anonymous> (jquery.min.js:2)

Could you check upper issue?

-Larry

Need update

last instagram update deny to view last post by username

Search by username stopped working

Search by username stopped working today. "Uncaught TypeError: Cannot read property 'user' of undefined".

Search by hashtag still working

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.