Sam Whiffing
Sam Whiffing

Reputation: 11

How to use PHP Instagram Signature with AJAX?

I'm stuck on the new Instagram API, where it is a requirement to use an Enforced Signed request, that uses both an Access Token and the Client Secret to make a Signature.

If anyone has any time at all to look, I would really appreciate it

I have generated the Signature here using PHP... http://samwhiffing.co.uk/nin3lives-feed/instagram.php

How do I implement it into this $.ajax request?

I tried this but it didn't work...

$.ajax({
  type: 'GET',
  dataType: 'jsonp',
  cache: false,
  url: 'samwhiffing.co.uk/nin3lives-feed/instagram.php',
  success: function(res) {
    for (var i = 0; i < 4; i++) {
      $('#instagram-feed').append( addPhoto( res.data[i] ) );
    }
  }
});

I also tried manually entering it here, which didn't work either...

$.ajax({
  type: 'GET',
  dataType: 'jsonp',
  cache: false,
  url: 'https://api.instagram.com/v1/users/self/media/recent/?sig=c3d9934a58bee276ba43a421d8454a2d6efff3c58140efff07782a64a0e3587b',
  success: function(res) {
    for (var i = 0; i < 4; i++) {
      $('#instagram-feed').append( addPhoto( res.data[i] ) );
    }
  }
});

This is the documentation: https://www.instagram.com/developer/secure-api-requests/

Thanks,

Sam

Upvotes: 1

Views: 477

Answers (1)

Javier
Javier

Reputation: 64

You need obtain the correct ACCES-TOKEN before to start.

You can read this post (How to obtain Acces Token).

Your token need a similar structure:
'your_ID'.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

When you've the correct token you can obtain results.

    var url='https://api.instagram.com/v1/users/self/?access_token='(YOUR-ACCESS-TOKEN)
    $.ajax({
            type: "GET",
            dataType: "jsonp",
            cache: false,
            url: url ,
            success: function(data) {
                    // Here the response obtained                               
            }

    });

If all is rigth you can obtain a results like this.

"data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }

Upvotes: 1

Related Questions