【问题标题】:How to Curl PHP SpeakerDeck.com Oembed URL如何卷曲 PHP SpeakerDeck.com Oembed URL
【发布时间】:2014-09-29 16:27:39
【问题描述】:

你能帮我弄一下 PHP Speakerdeck.com oembed URL

我试过这个,但它返回任何东西。

<?php
$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
function get_data($url){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
        $curlData = curl_exec($curl);
        curl_close($curl);
        return $curlData;
    }


get_data($url);
?>

【问题讨论】:

  • 编辑你的问题很好,但完全改变它意味着试图帮助你的人需要重新调试它。
  • 试试 echo get_data($url);在底部。

标签: php curl oembed


【解决方案1】:

您的代码对我有用。也许你的问题应该更清楚。你的意思是你想抓取网页的内容?

如果你想获取 http 返回码(你的代码),这可行:

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$head = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
print_r($httpCode);
curl_close($ch);

如果你想要网页内容:

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
//you can do some error checking if you want here.
print_r($page);
curl_close($ch);

为您的新代码:

get_data($url);

尝试:

echo get_data($url);

【讨论】:

  • 对我来说没有响应,上面的代码返回 0
  • 我复制粘贴了确切的代码,然后我得到了回复。您是编辑还是复制粘贴?
  • 1) 确保注释行。 2) 捕获 curl_exec return 3) print_r 正确的变量(curl_exec return)
  • echo get_data($url);试过这个页面是空白没有反应
  • PHP版本有问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
相关资源
最近更新 更多