2013-11-22 41 views
0

我連接到traileraddicts api,但是當我將頁面加載到服務器時,我收到此消息。連接到捲曲和顯示api

注意:嘗試在第20行的/heima/sth132/.public_html/Lokaverkefnireal/php/trailers.php中獲取非對象的屬性警告:爲/ usima/sth132 /.public_html中的foreach()提供的無效參數/Lokaverkefnireal/php/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>';  

    } 
?> 

回答

0

你應該從https您的捲曲URL協議更改爲http

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

沒有那dosent工作感謝雖然 – jonjonson

+0

@jonjonson你得到什麼錯誤?因爲我已經調試過它並通過上述解決方案獲得瞭解決方案。 – Parixit

0

問題似乎來自你的捲曲的URL,嘗試改變HTTPS對HTTP,這個工作對我來說

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