【问题标题】:Authentication problem with WufooWufoo 的身份验证问题
【发布时间】:2011-02-25 17:17:01
【问题描述】:

我设置了一个Wufoo 表单,其中仅包含管理员部分,只有在我登录时才会显示。我通读了Wufoo API documentation,我可以让身份验证工作,但是当我尝试访问表单时在我进行身份验证后,它说我需要进行身份验证。这就是我目前所拥有的(子域、api 密钥和表单 ID 已更改)

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$curl1 = curl_init('http://fishbowl.wufoo.com/api/v3/users.xml');
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl1, CURLOPT_USERPWD, 'AOI6-LFKL-VM1Q-IEX9:footastic');
curl_setopt($curl1, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl1, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl1, CURLOPT_USERAGENT, 'Wufoo Sample Code');

$response = curl_exec($curl1);
$resultStatus = curl_getinfo($curl1);

if($resultStatus['http_code'] == 200) {
    echo 'success!<br>';
} else {
    echo 'Call Failed '.print_r($resultStatus);
}

$curl2 = curl_init("http://fishbowl.wufoo.com/api/v3/forms/w7x1p5/entries.json"); 
curl_setopt($curl2, CURLOPT_HEADER, 0);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl2);
curl_close ($curl2);
echo $response;

curl_close($curl1);

?>

无论我在调用$curl2 之前还是之后关闭$curl1,我都会在屏幕上看到相同的消息:

成功!

您必须进行身份验证才能获得 在好东西。

而且我知道 api、子域和表单 id 都是正确的。

最后一个额外的问题...我可以使用 Ajax 来代替所有这些吗? - 我将在其上显示表单的页面已被限制为管理员访问权限,因此公开 API 无关紧要。

【问题讨论】:

    标签: php


    【解决方案1】:

    好的,我做了一些挖掘工作。

    事情就是这样,您需要对要对 API 进行的每个调用进行身份验证。 我注意到在您使用的 URL (http://fishbowl.wufoo.com/api/v3/users.xml) 中,您使用了 http,但 API 要求您使用 https。如果您尝试通过正常的 HTTP 协议进行访问,您只会收到 You must authenticate to get at the goodies. 消息。

    因此,对于您的第二次通话,您需要再次重新进行身份验证。

    您的代码应如下所示:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    $curl1 = curl_init('https://fishbowl.wufoo.com/api/v3/users.xml');
    curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl1, CURLOPT_USERPWD, 'AOI6-LFKL-VM1Q-IEX9:footastic');
    curl_setopt($curl1, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl1, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl1, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl1, CURLOPT_USERAGENT, 'Wufoo Sample Code');
    
    $response = curl_exec($curl1);
    $resultStatus = curl_getinfo($curl1);
    
    if($resultStatus['http_code'] == 200) {
        echo 'success!<br>';
    } else {
        echo 'Call Failed '.print_r($resultStatus);
    }
    
    $curl2 = curl_init("https://fishbowl.wufoo.com/api/v3/forms/w7x1p5/entries.json"); 
    curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl2, CURLOPT_USERPWD, 'AOI6-LFKL-VM1Q-IEX9:footastic');
    curl_setopt($curl2, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl2, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl2, CURLOPT_USERAGENT, 'Wufoo Sample Code');
    $response = curl_exec($curl2);
    curl_close ($curl2);
    echo $response;
    
    curl_close($curl2);
    
    ?>
    

    关于您关于所有这些都在 AJAX 中完成的问题,目前不可能,因为 Wufoo 不支持 JSONP 回调(允许跨域 AJAX 请求)。 (如果您不知道我在说什么,请阅读 this other SO question)但是,如果您想将此功能插入 AJAX,您可以在本地服务器上对您的 PHP 脚本进行 AJAX 调用。 PHP 脚本将执行与上述类似的操作,使用 Wufoo 进行身份验证。

    【讨论】:

    • 您好,先生!感谢您的回答,遗憾的是我的免费虚拟主机设置了安全模式,因此我无法访问任何安全 URL。但是如果我使用http://,你的回答对我有用,但显然我仍然无权查看仅限管理员的数据;不过,我现在正在接收公共数据。所以谢谢!...我想我需要寻找另一个没有设置安全模式的免费 php 托管站点。
    • 嗯,实际上我检查了我的托管服务并且安全模式已关闭...当我使用https:// 时,页面永远不会完成加载。如果我将 CURLOPT_FOLLOWLOCATION 设置为 true,我会收到此错误:curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in...
    • 抱歉,上面有一个错字,我使用了$curl1 而不是$curl2。这可能是由于没有设置这些选项,这就是它没有返回的原因。 :)
    • 实际上我注意到了错别字并已修复它们......当我尝试访问任何https:// 站点时,页面永远不会完成加载。我猜这是主机设置。
    猜你喜欢
    • 1970-01-01
    • 2013-07-23
    • 2015-08-25
    • 2010-11-17
    • 2019-06-19
    • 2018-10-08
    • 2011-02-14
    • 2011-07-03
    相关资源
    最近更新 更多