Home javascript How to work with Instagram API?

How to work with Instagram API?

Author

Date

Category

The task arose to display a few fresh photos from Instagram on the site. I registered in https://www.instagram.com/developer/register/ and received an identifier

But when trying to execute the code …

$. Ajax ({
    url: 'https://api.instagram.com/oauth/authorize/',
    datatype: 'json',
    Type: 'Get',
    Data: {Client_ID: '[_My_Client_ID_]'},
    SUCCESS: FUNCTION (Response) {
     Console.log (Response);
    },
    Error: Function (JQXhr, TextStatus, Errorthrown) {
     Console.log (JQXhr, TextStatus, Errorthrown);
    }
   });
  & lt; / script & gt;

An error occurs:

No ‘Access-Control-Allow Origin’ Header Is Present On the Requested
Resource. Origin ‘http: // [domain ] .ru ‘ is therefore not alowed
Access.

Tell me how to solve this problem.


Answer 1, Authority 100%

The task was solved by writing the code on the back-end using CURL:

try {
    $ ch = curl_init ();
    CURL_SETOPT ($ CH, Curlopt_ssl_verifypeer, false);
    CURL_SETOPT ($ CH, Curlopt_returntransfer, True);
    curl_setopt ($ ch, curlopt_httpheader, array ('x-Requested-with' = & gt; 'xmlhttprequest'));
    curl_setopt ($ CH, Curlopt_URL, $ URL);
    $ result = curl_exec ($ CH);
    CURL_CLOSE ($ CH);
    $ result = json_decode ($ result, true);
  } Catch (\ Exception $ E) {
    $ result = null;
  }

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions