0

I realise there are loads of posts our there going through how to do this, but can someone just convert the following cURL ito php cURL please? Please note: there are the stardard post data bits, but then the YXYXY:WZWZWZ bit as well...

curl -X POST -d 'grant_type=password&username=ABABABA&password=CDCDCDC' --user 'YXYXYXYXY:WZWZWZWZWZWZW' https://www.reddit.com/api/v1/access_token

TIA.

Matt Cowley
  • 2,164
  • 2
  • 18
  • 29
  • Doesn't cover the YXYXY:WZWZW bit @Overdrivr – Matt Cowley Jun 02 '16 at 13:07
  • Does this one fixes your problem ? http://stackoverflow.com/questions/20064271/how-to-use-basic-authorization-in-php-curl – Overdrivr Jun 02 '16 at 13:09
  • `--user 'YXYXYXYXY:WZWZWZWZWZWZW'` is handled by `CURLOPT_USERPWD ` in http://php.net/manual/en/function.curl-setopt.php. Read the manual, please. – ceejayoz Jun 02 '16 at 13:34
  • Thanks @ceejayoz. Why has it been marked as a duplicate. The question linked doesn't cover what I needed. – Matt Cowley Jun 02 '16 at 14:00
  • @MattCowley It's a duplicate of several questions. Overdrivr linked to one dealing with username/password, but only one link can be marked as the duplicate answer. Ultimately, StackOverflow isn't intended as a replacement for reading the documentation, where your use case is easily addressed. – ceejayoz Jun 02 '16 at 14:09

1 Answers1

0
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://www.reddit.com/api/v1/access_token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "client_id=CLIENT_ID&response_type=TYPE&
    state=RANDOM_STRING&redirect_uri=URI&scope=SCOPE_STRING");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);
 print_r($server_output);
//if ($server_output == "OK") {  pr($server_output);} else { echo "asdsa"; }

?>

user this way