2014-12-21 46 views
0

使用Instagram的API,我能夠回到我自己最近的照片:Instagram的API - 獲取其他用戶的照片

https://api.instagram.com/v1/users/[my-user-id]/media/recent?client_id=[my-client-id] 

不過,我無法用[other-user-id]檢索其他用戶,即使我可以在API console中這樣做。下面是我使用

$.ajax({ 
    type:'post', 
    url:'https://api.instagram.com/v1/users/[my-user-id]/media/recent?client_id=[client-id]', 
    dataType:'jsonp', 
    success:function(data){ 
     console.log('got data ', data) 
    } 
}) 

注意,使用後避免與Access-Control-Allow-Origin問題的JavaScript代碼。

+0

我沒有任何問題使用上面的代碼從另一個用戶檢索數據?你確定你試圖獲得媒體的用戶有公開的個人資料嗎? – Cyclonecode

+1

有趣的 - 我不知道人們有非公開的配置文件。我可以與其他一些用戶(20053826,brunomars)做到這一點。任何想法如何訪問我關注的人? – mike

+0

我不太確定,我認爲用戶必須允許您的客戶端查看配置文件。 – Cyclonecode

回答

1

我想你想使用oAuth而不是客戶端ID。

這裏是一個例子。

第1步:將用戶重定向到instagram登錄。

<a href="https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token">Instagram Login</a> 

在返回時,剝離出的訪問令牌是這樣的:

function AccessToken(value) { 
    this.value = value; 
} 

function getInstagramAccessToken() { 
    var hash = location.hash.replace('#', '') 
    if(hash.indexOf("access_token") >= 0){ 
     instagramToken = new AccessToken(hash) 
    }else{ 
     instagramToken = null; 
    } 
} 

步驟2:通過身份驗證後,作出這樣的呼籲:

var photoList_Instagram = [] 
function getInstagramPhotoList(nextPageUrl) { 

    var requestUrl = 'https://api.instagram.com/v1/users/self/media/recent' + "?" 
    + instagramToken.value 

    if(nextPageUrl){ 
     requestUrl = nextPageUrl; 
    } 
    $.ajax({ 
     type : "GET", 
     dataType : "jsonp", 
     url : requestUrl, 
     success : function(response) { 
      response.data.forEach(function(photo){ 
       photoList_Instagram.push(photo); 
      }) 
      if (response.pagination.next_url) { 

       getInstagramPhotoList(response.pagination.next_url) 

      } else { 
       //your code here 
       foo(photoList_Instagram); 
      } 
     } 
    }); 
相關問題