lomse
lomse

Reputation: 4165

cURL code not working

I am trying this tutorial on this page: Tictail External App Tutorial. Based on this tutorial, one should make a curl call as shown below:

$ curl 'https://tictail.com/oauth/token' \
    -d 'client_id=YOUR_CLIENT_ID' \
    -d 'client_secret=YOUR_CLIENT_SECRET' \
    -d 'code=CODE' \
    -d 'grant_type=authorization_code'

To my knowledge, the above curl script could be rewritten in PHP as shown below:

$url = "https://tictail.com/oauth/token";
$url .= "?client_id=" . TT_CLIENT_ID;
$url .= "&client_secret=" . TT_CLIENT_SECRET;
$url .= "&code=" . MY_CODE;
$url .= "&grant_type=authorization_code";

$curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url
    ));

    $result = curl_exec($curl);
    var_dump($result);  //This gives: string(87) "405: Method Not Allowed" making me think that something wrong with my code. Could someone please confirm? 

Sorry I am new to cURL. Thanks.

Upvotes: 1

Views: 213

Answers (1)

Legionar
Legionar

Reputation: 7607

I guess, you have to curl your data as POST, you cant have it in your url. Add this to your code:

$data  = "client_id=" . TT_CLIENT_ID;
$data .= "&client_secret=" . TT_CLIENT_SECRET;
$data .= "&code=" . MY_CODE;
$data .= "&grant_type=authorization_code";

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

Upvotes: 4

Related Questions