Reddit POST请求-错误403(php / curl)

时间:2019-07-31 16:55:27

标签: php curl reddit

我正在尝试连接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);

0 个答案:

没有答案