簡體   English   中英

File_get_content無法打開流

[英]File_get_content failed to open the stream

我已經檢查了以前的相關線程,但是我的問題涉及特定的可讀性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

您似乎正在從Facebook獲取內容。

由於您的錯誤403 FORBIDDEN,我想說您的解析器/代碼無權訪問您正在訪問的Facebook頁面,因此由於隱私設置而被拒絕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM