Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to shopify app development and I am using the API. While doing the OAuth for the app I am stuck at the step where we have to retrieve the permanent access token. I have the access code from the first step and afterwards I am POSTing the the three parameters using cURL.

This is the code that I have written:

 <?php $code=$_GET['code'];
 $client_id="c0356e832edeb92d5e30bce50ddb039f";
 $client_secret="xxx";
 $url="https://smokeallover-2.myshopify.com/admin/oauth/access_token";
 $fields_string="";
 $fields = array('client_id' => urlencode($client_id),
          'client_secret' => urlencode($client_secret),
          'code' => urlencode($code));
 foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
 rtrim($fields_string, '&');
 $ch = curl_init();
 curl_setopt($ch,CURLOPT_URL, $url);
 curl_setopt($ch,CURLOPT_POST, count($fields));
 curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
 curl_setopt(
 $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded'));           
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
 $result = curl_exec($ch);
 if($result === false)
 echo curl_error($ch);
 curl_close($ch);
 echo $result;
 ?>

but the result is error:

invalid request.

I have found many questions similar to this on stackoverflow and have tried reinstalling the app among other things.. I am not sure where to find the error as I am new to cURL, OAuth2 and shopify API.. I have figured out until this point. Please help me find a lead.

share|improve this question
    
Seems tha tI have found the glitch...I was refreshing the page and using the same code(the one generated in first step ) after editing my code..that is where I was wrong..we cannot use the same code again and again.So I started a new session and got the access token. –  Kunal Singh Jun 5 '13 at 13:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.