繁体   English   中英

使用curl和display连接到api

[英]connecting to api with curl and display

我正在连接到traileraddicts api,但是将页面加载到服务器时却收到此消息。

注意:尝试在第20行的/heima/sth132/.public_html/Lokaverkefnireal/php/trailers.php中获取非对象的属性警告:/heima/sth132/.public_html/Lokaverkefnireal/php中为foreach()提供的参数无效/trailers.php,第20行

这是我的代码,你们能帮我解决这个问题吗???

<?php 
// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, "https://api.traileraddict.com/?featured=yes&count=8");

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

// load the previously downloaded XML page
$upcoming = simplexml_load_string($output);

foreach($upcoming->trailer as $x => $updates) 
{ 
   echo $updates->title; 
   echo '<br>'; 
   echo '<span style="font-size:x-small">Source: <a href="'. $updates->link .'">TrailerAddict</a></span>'; 
   echo '<br>'; 
   //now echo the embedded trailer 
   echo $updates->embed; 
   echo '<br><br>';     

    } 
?>

您应该将curl url协议从https更改为http

// set url
//please remove https
curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");

问题似乎来自您正在卷曲的URL,请尝试将https更改为http,这对我有用

 curl_setopt($ch, CURLOPT_URL, "http://api.traileraddict.com/?featured=yes&count=8");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM