to_header()); // print_r($headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $rsp = curl_exec($ch); $results = json_decode($rsp); print_r($results); ?> Thanks in advance"> oauth with curl - Forums

Forums

oauth with curl

bmowrey 10 Jan, 2015
Im trying to return values from a remote API using curl within PHP, but the form refuses to save, instead rendering a 404 every time, so im unable to even test this. Any ideas on the issue? is it the includes line? if so, how to include oAuth.php?
( please note that the code functions well on its own page)
Also do form variables need {bID} curly braces?

 <?php  
 require("OAuth.php");
// redacted from live page
//$bID=$_POST['bID'];
//$oNo=$_GET['oNo'];
$consumer_key  = "xxx"; 
$shared_secret = "xxx"; 
$url = "somedamnsite"; 

 $args = array(); 
   $args["bID"]=$bID; // <-- variable from form
   $args["orderNo"]=$oNo; // <-- variable from form

   $consumer = new OAuthConsumer($consumer_key, $shared_secret); 
   $request = OAuthRequest::from_consumer_and_token($consumer, NULL,"POST", $url, $args); 
   $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL); 
   $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args)); 
    
  // print_r($request);  

   $ch = curl_init(); 
   $headers = array($request->to_header()); 
  
//  print_r($headers); 
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_URL, $url); 
   curl_setopt($ch, CURLOPT_POST, true); 
   curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
   
   $rsp = curl_exec($ch); 
   $results = json_decode($rsp); 

   print_r($results);  
    ?>  


Thanks in advance
GreyHead 10 Jan, 2015
Hi bmowrey,

Is the problem that the form won't save in the Forms Manager? If so, please see this FAQ

Or is it that you get the 404 when you submit the form. If so, what is the URL that gives the 404 and is there any other useful message shown?

Is there some reason for not using the $form->data[''] array and/or the cURL action?

There are two - quite different contexts where you use curly brackets {}:

+ Where you want to re-publish form data in HTML without using <?php ?> tags e.g. in an email template you might use
Hi {first_name} {last_name},


+ Inside <?php ?> tags where you want to include a variable in a string - the string must be in double quotes e.g.
<?php
echo "Hi {$form->data['first_name']} {$form->data['last_name']},";
?>


Bob
bmowrey 11 Jan, 2015
Hi Bob- Im not sure of the distinction you mean in saving. However, the end result is that the form doesn't save and immediately presents a 404 located at this URL.
https://www.xxxxxxx.com/administrator/index.php?option=com_chronoforms5&act=save&save_act=apply
The form does save when that custom code is removed, however.

I had implemented this previously in a php page and simply wished to minimize recoding. it works alone, so why not just run it this way, thereby minimizing troubleshooting etc. I havent used the cURL methods, but it appears ill have to try that method. THank you for clarifying the curly braces uses, its much appreciated
bmowrey 11 Jan, 2015
The question is how to authenticate using oauth through curl as it appears the curl function only allows simple param exchange as opposed to allowing oauth. Is there some other method i can employ to make this happen or have i missed something obviou

One more question- Ive attempted to use the cURL method in CF but there is no obvious method for using oauth from within the cURL utility. How would one do that? At first blush this is a good reason to use the PHP custom code method

[[>> I have merged two different posts here and changed the topic name to keep the topic in one thread : Greyhead <<]]
GreyHead 14 Jan, 2015
Hi bmowbray,

To keep life simple I have merged your new thread back into this one and changed the topic - except that there is no formal merge method so I doubled up your last post.

As far as I can make out these are two ways of doing the same thing. You can either use the oAuth PHP in a custom code action - which may be the simplest way to go.

Or you can use the cURL action in which case you need to separate out the root URL and the arguments list as the action builds a URL.

Bob
This topic is locked and no more replies can be posted.