Using the postman, I send POST (my username and password are filled in):
https:
I get a response containing modhash and cookie. Then I send a second POST with a postman to:
https://en.reddit.com/api/comment?api_type=json&text=7/1/15TEST&thing_id=t1_csa56v2
with the following headings (XXX verified and completed):
User-Agent: XXX
Cookie: reddit_session=XXX
X-Modhash: XXX
This provides the correct answer, but when I try to do the same with CURL in my PHP, it answers USER_REQUIRED. Once again, I confirmed that the cookies and modhash are correct.
$name = 't1_csa56v2';
$text = 'NEWEST TEST 7/2/15 12:20am';
$url = 'https://en.reddit.com/api/comment';
$modhash = 'XXX';
$cookie = 'XXX';
$headerFields = array (
'User-Agent' => 'XXX',
'Cookie' => 'reddit_session='.$cookie,
'X-Modhash' => $modhash
);
$postFields = array (
'api_type' => 'json',
'text' => $text,
'thing_id' => $name
);
$field_string = http_build_query($postFields);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
$response = curl_exec($ch);
What am I doing wrong? Why can't I get the same answer?
POSTMAN Screenshot:

source
share