Skip to main content

Instagram API Integration to get Instagram feed to your website

To integrate the Instagram API in your website, you need you have to follow following process
  1. Log in to Instagram and open this page https://instagram.com/developer/clients/manage
  2. Click on the button «Register a New Client».
  3. Then Fill all the Mandatory fields, in Valid Redirect URIs specify your valid redirected URI and click «Register». Then click «Manage» button to obtain both Client ID and Client Secret of your just registered app.
  4. Use the Client ID and Client Secret to generate access token with this link https://rudrastyh.com/tools/access-token. You can find more info there as well.
A Short Introduction about sandbox mode
  • All newly created apps start in Sandbox Mode
  • Apps in Sandbox mode have access only to 20 latest media of an access token owner (and sandbox users invited to your app).
  • To avoid these restrictions you should send your app to approval.
We can get instagram feed in our website by two ways
  • By User ID
  • By a Username
How can we get Instagram feed in our website by Using User ID?
Following is the javascript code to get instagram feed into our website by using User ID
var token ='your access token',
userid=3679808080,
    num_photos =5;// how much photos do you want to get
 
$.ajax({
 url:'https://api.instagram.com/v1/users/'+userid+'/media/recent',// or /users/self/media/recent for Sandbox
 dataType:'jsonp',
 type:'GET',
 data:{access_token: token, count: num_photos},
 success:function(data){
  console.log(data);
  for( x indata.data){
         $('ul').append('<li> <img src="' + data.data[x].images.low_resolution.url'">+</li>');
  }
 },
 error:function(data){
  console.log(data);// send the error notifications to console
 }
});

How can we get Instagram feed in our website by Using Username?
Following is the JavaScript code to get instagram feed into our website by using Username.
var token ='your access token',
    username ='vksbomen',// vksbomen - my username :)
    num_photos =4;
 
$.ajax({// the first ajax request returns the ID of user rudrastyh
 url:'https://api.instagram.com/v1/users/search',
 dataType:'jsonp',
 type:'GET',
 data:{access_token: token, q: username},// actually it is just the search by username
 success:function(data){
  console.log(data);
  $.ajax({
   url:'https://api.instagram.com/v1/users/'+data.data[0].id+'/media/recent',// specify the ID of the first found user
   dataType:'jsonp',
   type:'GET',
   data:{access_token: token, count: num_photos},
   success:function(data2){
    console.log(data2);
    for(x in data2.data){
    $('ul').append('<li> <img src="' + data.data[x].images.low_resolution.url'">+</li>');
    }
   },
   error:function(data2){
    console.log(data2);
   }
  });
 },
 error:function(data){
  console.log(data);
 }
});
How to generate access token?
Follow the below link to generate your access token

Comments

Popular posts from this blog

GraphQL With Ruby

Now a day’s most of the web or mobile applications fetch data from server which is stored in a database. REST API provides an interface to stored data that require by the applications. GraphQL is a query language for REST API's not for server databases. It is database agnostic and effectively can be used in any context where an API is used. GraphQL provide platform for declarative data fetching where client need to specify what data needs from API in response. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for. GraphQL minimizes the amount of data that needs to be transferred over the network and improves applications operating under these conditions. Introduction to GraphQL API on Ruby on Rails Start with adding gem in Gemfile gem ‘graphql’ Run command bundle install Run command rails generate graphql:install Above command will add gr

Best In Place Gem In Ruby On Rails Tutorial

The best_in_place gem is the easiest solution for in place editing in Ruby on Rails. This gem provides functionality of “in place editing” in ruby on rails without writing any extra ajax code. It supports text inputs, textarea, select dropdown, checkboxes, jQuery UI Datepickers, etc. Also Displays server-side validation Installation Steps of “best_in_place” Gem : Installing best_in_place is very easy and straight-forward. Just begin including the gem in your Gemfile: gem ‘best_in_place’ After that, specify the use of the jquery and best in place javascripts in your application.js, and optionally specify jquery-ui if you want to use jQuery UI datepickers: //= require jquery //= require best_in_place //= require jquery-ui //= require best_in_place.jquery-ui Then, just add a binding to prepare all best in place fields when the document is ready: $(document).ready(function() { /* Activating Best In Place */ jQuery(".best_in_place").best_in_place(); });

Data scraping in Ruby on Rails using Nokogiri and Mechanize Gem

What is Data scraping? Website/Data  Scraping  is a technique to operating large amounts of  data  from websites whereby the  data  is extracted and displayed in own sites or it can be stored to a File/Database. Data scraping is basically used where the websites does not provides API. Some Applications do not provide API to collect records. For the same , Data Scraping technique is used. The data can be scraped using Nokogiri Gem. The steps are required: Add the gem “gem ‘nokogiri’, ‘~> 1.8’, ‘>= 1.8.1'” . Then run the bundle install Add the “require ‘nokogiri'” , “require ‘open-uri'” line where you will write the code for the scraping. The controller of the page will look like below: The view of the code of view page will look like : The result in our application will look like: Mechanize Gem in rails The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follo