首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php的alchemyAPI不工作

php的alchemyAPI不工作
EN

Stack Overflow用户
提问于 2013-10-21 17:27:45
回答 2查看 231关注 0票数 0

我正在尝试使用AlchemyAPI的php sdk。我正在运行他们的Github page上给出的相同示例。但是当我尝试运行这个例子时,我得到了这个错误信息-

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

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

代码语言:javascript
复制
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');
        }
    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-10-22 07:29:34

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

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

票数 0
EN

Stack Overflow用户

发布于 2014-07-21 14:58:46

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19490716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档