How to work with the Instagram API?

There was a task to display on the site a few fresh photos from Instagram. Registered in https://www.instagram.com/developer/register/ and got the ID CLIENT ID

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

        }
      });
    </script>

An error occurs:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://[domain].ru' is therefore not allowed access.

Mistake

Tell me how to solve this problem.

Author: MSDN.WhiteKnight, 2016-09-24

1 answers

The problem was solved by writing back-end code 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' => 'XMLHttpRequest' ) );
        curl_setopt($ch, CURLOPT_URL,$url);
        $result=curl_exec($ch);
        curl_close($ch);

        $result = json_decode( $result, true );

    } catch ( \Exception $e ) {

        $result = null;

    }
 1
Author: Skim, 2016-09-25 14:23:40