CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 14, 2012, 11:01:25 PM Last edit: July 29, 2012, 08:13:05 AM by CA Coins |
|
Does anybody have working code for connecting to the CampBX API with PHP? I can get market data and account data if I post the auth info through a form, but I can't seem to connect to account data with cURL or file_get_contents in PHP. The linked PHP library by Brandon Beasley also doesn't work for me for some reason. Can't get a response from their support either for the last 2 weeks. If anybody has working code to get account info via cURL or file_get_contents in PHP, I would much appreciate it. Thanks.
EDIT: Added 5 BTC bounty for whoever helps me solve this problem. Thanks.
|
|
|
|
|
|
|
|
|
The grue lurks in the darkest places of the earth. Its favorite diet is adventurers, but its insatiable appetite is tempered by its fear of light. No grue has ever been seen by the light of day, and few have survived its fearsome jaws to tell the tale.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 14, 2012, 11:12:01 PM |
|
Have you requested api credentials access? You have the request access. There is no on and off in the user interface. Then you can use your existing credentials.
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 14, 2012, 11:22:13 PM |
|
Yeah, I have been granted API access. Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc. But if I try to post the same data with cURL, I get "Bad Request Your browser sent a request that this server could not understand. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request." my cURL parameters: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ' https://CampBX.com/api/myfunds.php');curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword'); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); print_r($res); curl_close($ch); if I use file_get_contents, I just get a blank page.
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 14, 2012, 11:34:14 PM |
|
Yeah, I have been granted API access. Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc. But if I try to post the same data with cURL, I get "Bad Request Your browser sent a request that this server could not understand. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request." my cURL parameters: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ' https://CampBX.com/api/myfunds.php');curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword'); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); print_r($res); curl_close($ch); if I use file_get_contents, I just get a blank page. Try: $params['user'] = "username"; $params['pass'] = "password"; $postData = http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ' https://CampBX.com/api/myfunds.php');curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); print_r($res); curl_close($ch);
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 15, 2012, 12:42:01 AM |
|
Yeah, I have been granted API access. Interestingly, if I post the credentials through a form, then I can access myfunds, myorders, etc. But if I try to post the same data with cURL, I get "Bad Request Your browser sent a request that this server could not understand. Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request." my cURL parameters: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ' https://CampBX.com/api/myfunds.php');curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=myUser&pass=myPassword'); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); print_r($res); curl_close($ch); if I use file_get_contents, I just get a blank page. Try: $params['user'] = "username"; $params['pass'] = "password"; $postData = http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ' https://CampBX.com/api/myfunds.php');curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); print_r($res); curl_close($ch); Thanks for your help, but I got the same response. "Bad request..."
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 15, 2012, 01:02:28 AM |
|
Any output in your apache error_log?
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 15, 2012, 01:14:06 AM |
|
I am actually running this on win server 2008. I don't see anything in the PHP error log or the IIS error log. I can access the other exchanges (mtgox, bitfloor, intersango) with no issues. Weird it is just with CampBX.
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 19, 2012, 03:57:14 AM |
|
I am surprised nobody has working code for accessing CampBX API with PHP. Maybe it is just my setup? Either way, I am going to throw in a 5 BTC bounty to whoever helps me solve this problem. Please post or PM me. Thanks.
|
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 19, 2012, 04:01:34 AM |
|
Thanks for the link, but his library doesn't work for me for some reason.
|
|
|
|
gweedo
Legendary
Offline
Activity: 1498
Merit: 1000
|
|
July 19, 2012, 04:03:24 AM |
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BTChash; '.php_uname('s').'; PHP/'.phpversion().')'); add this to your code, i looked at his source and this how he gets it to work
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 19, 2012, 02:15:56 PM |
|
CA Coins,
The code i posted works fine with my credentials on a CentOS server. I think it an MS Server issue. Have you contacted Keyur directly. He's been very helpful with my requests. When you do find a solution please post.
Thanks.
|
|
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 20, 2012, 04:16:43 AM Last edit: July 21, 2012, 04:17:13 AM by CA Coins |
|
Thanks for the replies. I will do some testing in the next couple of days and report back the results. Thanks.
EDIT: Still no go. I verified that I am running php 5.3.9, curl 7.21.7 with openssl 0.9.8r. I tried adding the cert and it didn't solve the problem. I also tried running BCB's code on Ubuntu 11.10, Apache 2.0, PHP 5.3.6, curl 7.21.6, openssl 1.0.0e. I think something is not set correctly and the CampBX server is still rejecting my requests with the bad request error. I don't see any errors in the Apache error log either. I am going to try contacting CampBX again to see if they can find anything in their logs.
|
|
|
|
drakahn
|
|
July 25, 2012, 10:58:57 AM |
|
What about $params['user'] = "username"; $params['pass'] = "password"; $postData = http_build_query($params, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, " https://CampBX.com/api/myfunds.php"); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); $res = curl_exec($ch); print_r($res); curl_close($ch); ?
|
14ga8dJ6NGpiwQkNTXg7KzwozasfaXNfEU
|
|
|
CA Coins (OP)
Donator
Sr. Member
Offline
Activity: 305
Merit: 250
|
|
July 28, 2012, 07:55:50 PM |
|
Thanks for the suggestion, but still getting a 404 bad request error with the code below. $params['user'] = "myUser"; $params['pass'] = "myPass";
$postData = http_build_query($params, '', '&');
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://CampBX.com/api/myfunds.php"); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); //with or without: curl_setopt($ch, CURLOPT_CAINFO, "path/cacert.crt");
$res = curl_exec($ch); print_r($res); curl_close($ch);
|
|
|
|
scribe
|
|
July 28, 2012, 08:48:55 PM |
|
Does curl_error() give you anything? http://php.net/manual/en/function.curl-error.phpLooking at the curl_setopt() page has some things you could try ( http://php.net/manual/en/function.curl-setopt.php): Try using basic auth with: curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); Try using different SSL versions: curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2 The manual page says CURLOPT_SSL_VERIFYHOST can be either 1 or 2 with 2 being the default, so try 1 (instead of 0): curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); Otherwise maybe it's something to do with encodings being used - see the CURLOPT_ENCODING option. If there's a way to show the headers you're sending, you could try comparing what you're sending across different machines, and if one works, what difference in headers there are.
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 28, 2012, 11:01:16 PM |
|
curl_setopt($curl,CURLOPT_POST, true);
you forgot this so it will send as a post Gweedo, That is redundant when you are already calling curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); Try it.
|
|
|
|
paraipan
In memoriam
Legendary
Offline
Activity: 924
Merit: 1004
Firstbits: 1pirata
|
|
July 28, 2012, 11:19:05 PM |
|
Watching thread, and the skills some of you show off in here.
|
BTCitcoin: An Idea Worth Saving - Q&A with bitcoins on rugatu.com - Check my rep
|
|
|
unclemantis
Member
Offline
Activity: 98
Merit: 10
(:firstbits => "1mantis")
|
|
July 29, 2012, 01:03:23 AM |
|
sudo apt-get install ruby1.9.1 Solved! 19nUeM1qJmkpr8KYf9frtfWj6MCX7jpjb
|
|
|
|
|