简体   繁体   English

尝试访问 Factual API 时出现 PHP 错误

[英]PHP error when trying to access Factual API

I am using WAMP for my PHP framework.我正在将 WAMP 用于我的 PHP 框架。 I am trying to test this code我正在尝试测试此代码

<?php
require_once "C:\wamp\www\factual-php-driver-master\Factual.php";
$factual= new Factual("/*API Key*/","/*API Secret*/");

$query= new FactualQuery;
$query->limit(3);
$res= $factual->fetch("places", $query);
print_r($res->getData());
?>

The PATH to my Factual.php file is absolutely correct but the file returns the following errors我的 Factual.php 文件的 PATH 绝对正确,但该文件返回以下错误

Warning: require_once(C:\\wamp\\wwwactual-php-driver-master\\Factual.php): failed to open stream: Invalid argument in C:\\wamp\\www\\foodmeets\\restaurants.php on line 2警告:require_once(C:\\wamp\\wwwactual-php-driver-master\\Factual.php):无法打开流:第 2 行 C:\\wamp\\www\\foodmeets\\restaurants.php 中的参数无效

Fatal error: require_once(): Failed opening required 'C:\\wamp\\wwwactual-php-driver-master\\Factual.php' (include_path='.;C:\\php\\pear') in C:\\wamp\\www\\foodmeets\\restaurants.php on line 2致命错误:require_once():在 C:\\wamp\\www\\ 中打开所需的 'C:\\wamp\\wwwactual-php-driver-master\\Factual.php' (include_path='.;C:\\php\\pear') 失败第 2 行的 foodmeets\\restaurants.php

Please note I had performed the testing of the PHP install environment using the command请注意,我已经使用以下命令对 PHP 安装环境进行了测试

php -f test.php yourFactualKey yourFactualSecret [logfile]

as mentioned in the Factual Driver(V3) for PHP on Github( https://github.com/Factual/factual-php-driver )如 Github 上 PHP 的 Factual Driver(V3) 中所述( https://github.com/Factual/factual-php-driver

您必须转义 \\f (\\f 元字符用于查找换页符。)

require_once "C:\wamp\www\\factual-php-driver-master\Factual.php";

Your backslashes is converted into special chars by PHP. PHP 将您的反斜杠转换为特殊字符。 For instance, ... arrays\\news.php gets turned into例如, ... arrays\\news.php变成了

...arrays ...数组

ews.php ews.php

You should escape them like this:你应该像这样逃避他们:

$path = "C:\\NucServ\\www\\vv\\static\\arrays\\news.php"; $path = "C:\\NucServ\\www\\vv\\static\\arrays\\news.php"; Or use singles, like this:或者使用单打,像这样:

$path = 'C:\\NucServ\\www\\vv\\static\\arrays\\news.php'; $path = 'C:\\NucServ\\www\\vv\\static\\arrays\\news.php';

Also, your if is messed up.另外,你的 if 搞砸了。 You shouldn't fopen the file again.您不应再次打开该文件。 Just use your $fp which you already have.只需使用您已有的 $fp 即可。

Source failed to open stream: Invalid argument无法打开流:无效参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM