【问题标题】:AngularJS API GET requestAngularJS API GET 请求
【发布时间】:2015-08-27 17:51:10
【问题描述】:

我相信我正确地包含了我的访问令牌,所以我有点困惑为什么我仍然收到来自https://www.api.imgur.com/3/albumPermission 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

=============Update-2===================

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

【问题讨论】:

    标签: angularjs api get authorization imgur


    【解决方案1】:

    它应该通过$http 请求的headers 选项传递并且还将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
      })
    })
    

    【讨论】:

    • 试了几次还是得到403 Permission Denied
    • @PeterWard 从type: 'GET'method: 'GET'
    【解决方案2】:

    您是否尝试过在某个休息客户端或类似的东西中调用相同的请求?

    我喜欢用这个Advanced REST client

    【讨论】:

    • 我不使用我的用户可能没有安装的技术。这种请求不是 MEAN 应用程序无法处理的。
    • 高级 REST 客户端仅用于测试。我只是问你是否在其他休息客户端而不是你的客户端中测试过同样的请求。无论如何......在imgur文档中,我找到了一些关于这种请求的例子。它似乎适用于 POST 方法和此标头 Authorization: 'Bearer ' + token 而不是你的。
    猜你喜欢
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2016-02-12
    • 1970-01-01
    相关资源
    最近更新 更多