File_get_content无法打开流

时间:2014-01-17 04:04:46

标签: php parsing file-get-contents

我已检查过以前的相关主题,但我的问题涉及特定的可读性API。 我试图从网页获得最相关的图像。我正在使用红色https://www.readability.com/developers/api/parser

这是我的代码:

<?php
define('TOKEN', "1b830931777ac7c2ac954e9f0d67df437175e66e");
define('API_URL', "https://www.readability.com/api/content/v1/parser?url=%s&token=%s");
function get_image($url) {
    // sanitize it so we don't break our api url
    $encodedUrl = urlencode($url);

    $TOKEN = '1b830931777ac7c2ac954e9f0d67df437175e66e';
    $API_URL = 'https://www.readability.com/api/content/v1/parser?url=%s&token=%s';
//  $API_URL = 'http://blog.readability.com/2011/02/step-up-be-heard-readability-ideas';
    // build our url
    $url = sprintf($API_URL, $encodedUrl, $TOKEN);
    // call the api
    $response = file_get_contents($url);
    if( $response ) {
        return false;
    }
   $json = json_decode($response);
    if(!isset($json['lead_image_url'])) {
        return false;
    }
    return $json['lead_image_url'];
}

echo get_image('https://www.facebook.com/');

?>

错误:

Warning: file_get_contents(https://www.readability.com/api/content/v1/parser?url=https%3A%2F%2Fwww.facebook.com%2F&amp;token=1b830931777ac7c2ac954e9f0d67df437175e66e): failed to open stream: HTTP request failed! HTTP/1.1 403 FORBIDDEN in F:\wamp\www\inviteold\test2.php on line 16

1 个答案:

答案 0 :(得分:0)

您似乎从Facebook获取内容。

由于您的错误403 FORBIDDEN,我会说您的解析器/代码无权访问您正在访问的Facebook页面,因此您因隐私设置而被拒绝。