php - Reddit POST 请求 - 错误 403 (php/curl)
问题描述
我正在尝试连接 Reddit API 并以编程方式提交帖子。我已设法返回访问令牌,但在尝试进行实际提交时出现 403 错误。有什么建议吗?
获取访问令牌:(有效,返回令牌)
$ch = curl_init('https://www.reddit.com/api/v1/access_token?grant_type=client_credentials&username=USERNAME&password=PASSWORD');
curl_setopt($ch, CURLOPT_USERPWD, 'CLIENTID:CLIENTSECRET');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
$token = json_decode($return, true);
提交链接:(错误 403)
$ch = curl_init('https://www.reddit.com/api/v1/submit?kind=link&sr=news&title=TITLE&r=news&url='.urlencode('http://example.com'));
curl_setopt($ch, CURLOPT_USERPWD, 'CLIENTID:CLIENTSECRET');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: bearer ".$token['access_token']));
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch);
curl_close($ch);
return json_decode($return, true);
解决方案
推荐阅读
- asp.net - 我想知道我们如何在 asp.net mvc 5 中对静态图像设置分页
- continuous-integration - Concourse CI 作业无法卷曲到主机上的服务获取无法连接到 xxx.xxx.xxx。端口 9090:没有到主机的路由
- automation - 自动提取文件名中带有密码的压缩文件
- google-app-engine - 如何在 App Engine 文档中查看文档?
- python - 如何指定删除 .txt 文件中的短语,其中一个短语包含“x”另一个“x”和“y”(其中要删除 x 但不删除 x 和 y)
- amazon-web-services - 为什么一条 SQS 消息没有被删除而其他消息却被删除?
- php - 使用 PHP 进行简单的编码/解码,以避免传递容易猜到的 id
- javascript - 带有 JSON 的模式内的 Bootstrap 4 验证
- python - Udacity CS101:不确定这个嵌套字典问题是错误还是我遗漏了什么
- date - 减去 3 个月到 yyyymm 月份格式列 hive sql