I set up a Wufoo form with admin only portions that will only show up if I am logged in. I read through the Wufoo API documentation and I can get the authenication to work, but when I try to access the form after I authenticate, it says I need to authenticate. This is what I have so far (subdomain, api key & form id changed)
<?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);
?>
It doesn't matter if I close $curl1
before or after I call $curl2
, I get the same message on my screen:
success!
You must authenticate to get at the goodies.
and I know the api, subdomain and form id are all correct.
And one last bonus question... can I do all of this using Ajax instead? - the page I will be displaying the form on will alread开发者_StackOverflow中文版y be limited to admin access, so exposing the API shouldn't matter.
Okay I did some digging around.
Here's the thing, you need to authenticate for every call you want to make to the API.
I noticed that in the URL that you used (http://fishbowl.wufoo.com/api/v3/users.xml
) , you used http
but the API requires you to use https
. You will only get that You must authenticate to get at the goodies.
message if you attempt to access through the normal HTTP protocol.
So for your second call, you need to re-authenticate again.
Your code should then look like:
<?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);
?>
Regarding your question about all these being done in AJAX, it's not possible at the moment because Wufoo does not support JSONP callbacks (which allow for cross domain AJAX requests). (If you don't know what I'm talking about read this other SO question) However, if you want to plug this functionality into AJAX, you can do an AJAX call to your PHP script on the local server. The PHP script will do something like the above, authenticating with Wufoo.
精彩评论