2016-04-03 75 views
1

我被困在新的Instagram API中,它需要使用強制簽名請求,它同時使用Access Token和Client Secret來簽名。如何通過AJAX使用PHP Instagram簽名?

如果任何人有任何時候都看,我真的很感激它

我一直在使用PHP生成這裏的招牌... http://samwhiffing.co.uk/nin3lives-feed/instagram.php

如何落實到這個$就要求?

我試過,但沒有奏效...

$.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/

感謝,

山姆

回答

1

在開始之前,您需要獲得正確的ACCES-TOKEN

您可以閱讀本帖子(How to obtain Acces Token)。

你的令牌需要一個類似的結構:
「your_ID'.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx」

當你正確的標記,你可以得到結果。

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 
     }