【发布时间】: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 前面删除了 ':' 并且它可以工作
【问题讨论】: