doufei5537 2014-11-23 06:39
浏览 88
已采纳

无法检索reddit用户身份

I need only to authenticate Reddit users in to my website (in php). I'm using simple file_get_contents with stream_context_create for headers. I have already implemented Facebook user authentication.

For Reddit, I can successfully get an access_token. But when I GET request /api/v1/me with that access_token, I'm always getting HTTP/1.1 403 Forbidden.

Please Help.

This is the php code I'm using after I receive access_token

$opts = array('http' =>
    array(
    'method'  => 'GET',
    'header' => 'Authorization: bearer '.$result->access_token)
);
$context  = stream_context_create($opts);
$result = file_get_contents('https://oauth.reddit.com/api/v1/me', false, $context);

Is there anything I'm missing..

Here is the var_dump

array(7) {
  [0]=>  string(22) "HTTP/1.1 403 Forbidden"
  [1]=>  string(24) "Server: cloudflare-nginx"
  [2]=>  string(35) "Date: Sun, 23 Nov 2014 06:XX:XX GMT"
  [3]=>  string(38) "Content-Type: text/html; charset=UTF-8"
  [4]=>  string(17) "Connection: close"
  [5]=>  string(139) "Set-Cookie: __cfduid=XXXXXXXX; expires=Mon, 23-Nov-15 06:XX:XX GMT; path=/; domain=.reddit.com; HttpOnly"
  [6]=>  string(28) "CF-RAY: XXXXXXXXX-XXX"
}
  • 写回答

1条回答 默认 最新

  • dongne1560 2014-11-26 00:35
    关注

    Per the reddit API rules, you need to send a unique User-Agent with your request.

    Change your client's User-Agent string to something unique and descriptive, preferably referencing your reddit username.
    Example: User-Agent: flairbot/1.0 by spladug
    Many default User-Agents (like "Python/urllib" or "Java") are drastically limited to encourage unique and descriptive user-agent strings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么