Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP curl不';行不通_Php_Curl - Fatal编程技术网

PHP curl不';行不通

PHP curl不';行不通,php,curl,Php,Curl,嘿,伙计们,我正在尝试使用curl打印一个api。但到目前为止,我还没能让它发挥作用。也许你们能帮我。该网站使用api user和pass,两者都可以在我迄今为止编写的代码中查看。它的作用是获取$original_url,并根据模板id(即20016)为我们提供预览。您可以在这里阅读文档 希望你们能帮我看来你们想在一个不支持POST的url上发布http帖子 如果要获取20016模板数据,必须执行以下操作: $templateId = 20016; define("API_USER","...

嘿,伙计们,我正在尝试使用curl打印一个api。但到目前为止,我还没能让它发挥作用。也许你们能帮我。该网站使用api user和pass,两者都可以在我迄今为止编写的代码中查看。它的作用是获取$original_url,并根据模板id(即20016)为我们提供预览。您可以在这里阅读文档


希望你们能帮我

看来你们想在一个不支持POST的url上发布http帖子

如果要获取20016模板数据,必须执行以下操作:

$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);

这里有完整的API文档=>

问题出在哪里?它不起作用了怎么办?归还什么?您希望得到什么?您的支持以移动版本获取$original url的预览。这里是文档,请尝试打印出来而不进行JSON解码。可能是JSON格式不正确。此外,您可能会发现使用这个CURL包装器更容易:错误报告所说的
ini\u集(“display\u errors”,1);错误报告(E_全部)尝试获取第32行“return$output->site_name;”中非对象的属性@Paul Giragossian谢谢您的建议。
$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);