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.

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

报告相同问题?

悬赏问题

  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源