如何使用PHP Instagram签名与AJAX


How to use PHP Instagram Signature with AJAX?

我被困在新的Instagram API上,其中要求使用强制签名请求,该请求使用访问令牌和客户端密钥来进行签名。

如果有人有任何时间看,我真的很感激

我在这里使用PHP生成了签名。。。http://samwhiffing.co.uk/nin3lives-feed/instagram.php

如何在这个$.ajax请求中实现它?

我试过了,但没用。。。

$.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] ) );
    }
  }
});

我还试着在这里手动输入,但也不起作用。。。

$.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] ) );
    }
  }
});

这是文件:https://www.instagram.com/developer/secure-api-requests/

谢谢,

Sam

在开始之前,您需要获得正确的ACCES-TOKEN

您可以阅读这篇文章(如何获得Acces Token)。

您的代币需要类似的结构:
'your_ID'xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx'

当您拥有正确的令牌时,您可以获得结果。

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

如果一切顺利,你可以得到这样的结果。

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