AngularJS API GET请求

时间:2015-08-27 17:51:11

标签: angularjs api get authorization imgur

我相信我正确地包含了我的访问令牌,所以我对于为什么我仍然从https://www.api.imgur.com/3/album收到Permission Denied回复感到有点困惑。请参阅下面的代码:

$http.get('https://api.imgur.com/oauth2/authorize?client_id=MY_CLIENT_ID&response_type=token').then(function(json){
  console.log(json);
  $scope.token = json.config.headers.Authorization;
  $http({
    url: 'https://api.imgur.com/3/album/rX8ws',
    Authorization: $scope.token,
    type: 'GET'
  })
})

非常感谢任何帮助。

致以最诚挚的问候,

彼得

=============更新====================

调整了我在headers中封装授权密钥的请求,如下所示:

$http.get('https://api.imgur.com/oauth2/authorize?client_id=117ab4fd3e5fb89&response_type=token').then(function(json){
  console.log(json);
  $scope.token = json.config.headers.Authorization;
  $http({
    url: 'https://api.imgur.com/3/album/rX8ws',
    headers: {
       Authorization: $scope.token, //added token in headers
    },
    type: 'GET'
  })
})

仍然获得403 Permission Denied

=============更新-2 ==================

尝试将type: 'GET'更改为method: 'GET'无效。仍然会返回403 (Permission Denied)

2 个答案:

答案 0 :(得分:1)

应该通过headers请求&的$http选项传递同时将type: 'GET'更改为method: 'GET'

<强>代码

$http.get('https://api.imgur.com/oauth2/authorize?client_id=MY_CLIENT_ID&response_type=pin').then(function(json){
  console.log(json);
  $scope.pin = json.config.headers.Authorization;
  $http({
    url: 'https://api.imgur.com/3/album/rX8ws',
    headers: {
       Authorization: $scope.pin, //added token in headers
    }
    method: 'GET' //changed type to method
  })
})

答案 1 :(得分:0)

您是否曾尝试在某个休息客户端或类似的内容中调用此相同的请求?

我喜欢使用这个Advanced REST client