【问题标题】:Reddit Api endpoint returns 302 foundReddit Api 端点返回 302 found
【发布时间】:2015-04-14 05:31:34
【问题描述】:

我正在使用 CakePHP,并且我已经获得了 Reddit API 的访问令牌和刷新令牌,当我向像“/subreddits/popular.json”这样的端点发出获取请求时,它可以工作并返回 json。我的问题是当我向 /subreddits/mine/subscriber.json 发出获取请求时,我得到以下响应:

302 Found

The resource was found at https://www.reddit.com/subreddits/login.json?dest=https%3A%2F%2Foauth.reddit.com%2Freddits%2Fmine%2Fsubscriber.json%3Fcount%3D100%26limit%3D100; you should be redirected automatically.  "

为什么没有返回json?还是我错过了用于发送获取请求的代码是:

$endpoint = $this->ENDPOINT_OAUTH . '/subreddits/mine/subscriber.json';
$options = array(
    'header' => array(
    'Authorization' => $accessToken,
    'Accept' => 'application/json',
    'Content-Type' => 'application/json; charset=UTF-8'
    )
); 
$results = $HttpSocket->get($endpoint, $data, $options);

print_r('<pre>');
var_dump($results);
print_r('</pre>');

编辑:如果我添加到我的选项数组 'redirect' => true 然后它会重定向到 302 找到的 url,然后返回 200 ok 响应但没有数据

编辑 2:添加 'redirect' => true 之后,我从 Bearer TOKEN 前面删除了 ':' 并且它可以工作

【问题讨论】:

    标签: php cakephp reddit


    【解决方案1】:

    为了让它工作,我需要将 redirect => true 添加到我的选项参数中,以便它发送第二个 GET 请求。

    在设置我的访问令牌时,它是这样设置的:

    $accessToken = 'Bearer: ' . $accessToken;
    

    当我从 Bearer 前面删除 ':' 后,它开始工作并返回结果

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 2017-06-19
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 2012-10-30
      • 2020-12-05
      • 2020-12-25
      • 2013-07-27
      相关资源
      最近更新 更多