Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

$GET Request and curl setopt giving me issues

I'm currently developing a plugin using the Fitbit's API. It worked fine up until I added a CURL request which takes the access key and uses it to make a request for the access token. Here's how the page work currently:

1. input your fitbit API details Press submit - this puts the access key in the site URL.

2. $_GET grabs the access key

3. A CURL script further down on the page uses that key to call for the access token.

 

Parts 1, 2 and 3 worked fine up until adding the CURL. I'm wondering if anyone can see where I'm going wrong. Here's the code for the post request - if I comment this out my $_GET query gives me a valid access key, but if I put this back on the page it seems to mess up what is in the address bar to get:

 

$urlcode = "https://api.fitbit.com/oauth2/token";
$access_token_settings = array(
				'code' =>  $thecode,
				'grant_type' => "authorization_code",
				'client_id' =>  $clientid,
				'client_secret' => $secret,
				'redirect_uri' => $callback);

        $auth_headers = array("Content-Type: application/x-www-form-urlencoded", "Authorization: Basic {$auth}");
	
        $curlcode = curl_init($urlcode);
          curl_setopt($curlcode, CURLOPT_HTTPHEADER, $auth_headers); 	  
        curl_setopt($curlcode, CURLOPT_POST, true);     
       curl_setopt($curlcode, CURLOPT_POSTFIELDS, http_build_query($access_token_settings));      
        curl_setopt($curlcode, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curlcode,CURLOPT_TIMEOUT,1000);
        curl_setopt($curlcode, CURLOPT_SSL_VERIFYPEER, false);



     

$response = curl_exec($curlcode);
        curl_close($curlcode);
        
       


$autharray = ( array ) json_decode($response, true);


echo $response;
Best Answer
0 Votes
1 REPLY 1

What is the error you receive back from the Fitbit Web API? Can you capture the actual HTTP request (these are easier to debug than code)?

Best Answer
0 Votes