Reddit Api端点返回302找到

时间:2015-02-13 08:13:29

标签: php cakephp reddit

我正在使用CakePHP,当我向端点发出get请求时,我已经获得了Reddit API的访问令牌和刷新令牌,例如' /subreddits/popular.json& #39;它起作用并返回json。我的问题是当我向/subreddits/mine/subscriber.json发出get请求时,我收到以下响应:

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>');

编辑:如果我添加到我的选项数组&#39;重定向&#39; =&GT;如果为true,则重定向到302找到的url,然后返回200 ok响应,但没有数据

编辑2:添加&#39;重定向&#39; =&GT;是的,然后我删除了&#39;:&#39;从Bearer TOKEN前面开始工作

1 个答案:

答案 0 :(得分:1)

为了让它正常工作,我需要添加redirect =&gt;对我的options参数为true,以便它发送第二个GET请求。

设置我的访问令牌时,它设置如下:

$accessToken = 'Bearer: ' . $accessToken;

当我删除&#39;:&#39;从Bearer的前面然后工作并返回结果

相关问题