【问题标题】:alchemyAPI for php not working用于 php 的 alchemyAPI 不起作用
【发布时间】:2013-10-29 17:17:39
【问题描述】:

我正在尝试使用 AlchemyAPI 的 php sdk。我正在运行他们在Github page 上给出的相同示例。 但是当我尝试运行该示例时,我收到此错误消息-

 Warning: fclose() expects parameter 1 to be resource, boolean given in C:\wamp\www\twitter-analysis\alchemyapi.php on line 261

可能是什么原因?在 alchemyapi.php 中,这是发生警告的地方-

private function analyze($url, $params) {
        //Insert the base URL
        $url = $this->_BASE_URL . $url;

        //Add the API Key and set the output mode to JSON
        $url = $url . '?apikey=' . $this->_api_key . '&outputMode=json';

        //Add the remaining parameters
        foreach($params as $key => $value) {
            $url = $url . '&' . $key . '=' . $value;
        }

        //Create the HTTP header
        $header = array('http' => array('method' => 'POST', 'Content-type'=> 'application/x-www-form-urlencoded'));

        //Fire off the HTTP Request
        try {
            $fp = @fopen($url, 'rb',false, stream_context_create($header));
            $response = @stream_get_contents($fp);
            fclose($fp);
            return json_decode($response, true);
        } catch (Exception $e) {
            return array('status'=>'ERROR', 'statusInfo'=>'Network error');
        }
    }
}

【问题讨论】:

    标签: php alchemyapi


    【解决方案1】:

    fopen() 如果成功则返回资源,如果不成功则返回 false。 fopen 最有可能不起作用的情况是路径无效或您无权访问资源。

    这里提出了类似的问题:https://stackoverflow.com/questions/18636680/php-warning-fclose-expects-parameter-1-to-be-resource-boolean-given

    【讨论】:

      【解决方案2】:

      尝试在实时服务器上进行测试。 根据我的经验,它在本地服务器中出现错误,而在实时服务器中工作。

      【讨论】:

        猜你喜欢
        • 2016-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-30
        • 2017-01-08
        • 2012-07-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多