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;
}