0

Hey guys im trying to print one api using curl. but so far i wasnt able to get it to work. maybe you guys can help me. the website uses api user and pass both can be viewed in the code i made so far. what this does is it gets the $original_url and gives us a preview based on the template_id which is 20016. you can read the documentation here https://support.dudamobile.com/API/API-Use-Cases/Multiscreen-White-Label-Setup

$original_url = "http://rsportugal.org/index.html";
$data = array("template_id"=>"20016","url"=>$original_url);    
$data = json_encode($data);

define("API_USER","...");
define("API_PASS","...");

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/sites/multiscreen/templates');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");    

$output = curl_exec($ch);

if(curl_errno($ch)) {
    die('Curl error: ' . curl_error($ch));
}   
$output = json_decode($output);

curl_close($ch);

return $output->site_name;

hopefully you guys can help me

5
  • 1
    What is the issue? It doesn't work how? What is returned? What is expected? Commented Sep 5, 2014 at 11:06
  • your suppost to get a preview of the $original url in a mobile version . heres the documentation support.dudamobile.com/API/API-Use-Cases/… Commented Sep 5, 2014 at 11:08
  • Try printing out without JSON decoding. It could be the JSON is malformed. Further, you may find it easier to use this CURL wrapper: semlabs.co.uk/journal/… Commented Sep 5, 2014 at 11:11
  • What the error reporting says ini_set("display_errors",1); error_reporting(E_ALL); Commented Sep 5, 2014 at 11:17
  • Trying to get property of non-object in line 32 "return $output->site_name;" Commented Sep 5, 2014 at 11:20

1 Answer 1

2

It seems you want to do a http POST on an url that doesn't support POST.

If you want to get 20016 template data, you have to do so :

$templateId = 20016;

define("API_USER","..."); 
define("API_PASS","...");

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.dudamobile.com/api/sites/multiscreen/templates/' . $templateId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");    

$output = curl_exec($ch);

if(curl_errno($ch)) {
    die('Curl error: ' . curl_error($ch));
}   
$output = json_decode($output);

print_r($output);

curl_close($ch);

Full API documentation here => Duda mobile api Doc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.