Bitcoin Forum
May 12, 2024, 04:50:20 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: 1 2 [All]
  Print  
Author Topic: [CLOSED] Bounty 5 BTC - Acessing CampBX API with PHP  (Read 3149 times)
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 14, 2012, 11:01:25 PM
Last edit: July 29, 2012, 08:13:05 AM by CA Coins
 #1

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.
1715489420
Hero Member
*
Offline Offline

Posts: 1715489420

View Profile Personal Message (Offline)

Ignore
1715489420
Reply with quote  #2

1715489420
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 14, 2012, 11:12:01 PM
 #2

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 Offline

Activity: 305
Merit: 250


View Profile
July 14, 2012, 11:22:13 PM
 #3

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 Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 14, 2012, 11:34:14 PM
 #4

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 Offline

Activity: 305
Merit: 250


View Profile
July 15, 2012, 12:42:01 AM
 #5

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 Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 15, 2012, 01:02:28 AM
 #6

Any output in your apache error_log?
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 15, 2012, 01:14:06 AM
 #7

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 Offline

Activity: 305
Merit: 250


View Profile
July 19, 2012, 03:57:14 AM
 #8

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.
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
July 19, 2012, 04:00:19 AM
 #9

https://bitbucket.org/brandonbeasley/campbx-php/overview
the have a library

also you may need to do basic auth to use curl
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 19, 2012, 04:01:34 AM
 #10

Thanks for the link, but his library doesn't work for me for some reason.
gweedo
Legendary
*
Offline Offline

Activity: 1498
Merit: 1000


View Profile
July 19, 2012, 04:03:24 AM
 #11

Code:
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 Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 19, 2012, 02:15:56 PM
 #12

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.
unfinishe
Full Member
***
Offline Offline

Activity: 126
Merit: 100



View Profile
July 19, 2012, 04:58:06 PM
 #13

I'm no expert, but here are my suggestions:

First, make sure that you have OpenSSL installed. http://www.webhostingtalk.com/showthread.php?t=929949

Second, check to see if there are any proxy settings that aren't getting carried through. http://forums.iis.net/p/1173290/1973896.aspx#1973896

Third, try implementing the headers and curl options from the last post here: http://bytes.com/topic/php/answers/734722-getting-php-login-somewhere-post-username-password-then-get-cookies


Check out the results from my Bitcoin Survey Project!
https://bitcointalk.org/index.php?topic=88927.0
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 20, 2012, 04:16:43 AM
Last edit: July 21, 2012, 04:17:13 AM by CA Coins
 #14

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
Hero Member
*****
Offline Offline

Activity: 504
Merit: 500



View Profile
July 25, 2012, 10:58:57 AM
 #15

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 Offline

Activity: 305
Merit: 250


View Profile
July 28, 2012, 07:55:50 PM
 #16

Thanks for the suggestion, but still getting a 404 bad request error with the code below.

Code:
$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
Sr. Member
****
Offline Offline

Activity: 295
Merit: 250



View Profile WWW
July 28, 2012, 08:48:55 PM
 #17

Does curl_error() give you anything? http://php.net/manual/en/function.curl-error.php

Looking 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:

Code:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );


Try using different SSL versions:

Code:
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):

Code:
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.

blocknois.es Bitcoin music label. ~ New release: This Is Art

Read: Bitcoin Life | Wear: FUTUREECONOMY
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 28, 2012, 11:01:16 PM
 #18

Code:
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 Offline

Activity: 924
Merit: 1004


Firstbits: 1pirata


View Profile WWW
July 28, 2012, 11:19:05 PM
 #19

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 Offline

Activity: 98
Merit: 10


(:firstbits => "1mantis")


View Profile
July 29, 2012, 01:03:23 AM
 #20

Code:
sudo apt-get install ruby1.9.1

Solved!

19nUeM1qJmkpr8KYf9frtfWj6MCX7jpjb

PHP, Ruby, Rails, ASP, JavaScript, SQL
20+ years experience w/ Internet Technologies
Bitcoin OTC | GPG Public Key                                                                               thoughts?
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 29, 2012, 08:12:38 AM
 #21

Does curl_error() give you anything? http://php.net/manual/en/function.curl-error.php

Nope, no errors.

Quote

Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  

If verifyhost set as 1, then also need the line to point to the certificate, but here is a working code.

Code:
$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, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
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)");
curl_setopt($ch, CURLOPT_CAINFO, "path to certificate.crt");
//curl_setopt($ch,CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($ch, CURLOPT_SSLVERSION,3); // or try setting to 2  //This did the trick

$res = curl_exec($ch);
print_r($res);
echo 'Curl error: ' . curl_error($ch);
curl_close($ch);


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  
drakahn
Hero Member
*****
Offline Offline

Activity: 504
Merit: 500



View Profile
July 29, 2012, 08:24:15 AM
 #22

1MEYHC9c5gmJ4TPWCoFWW9Ey1TGLUjfMKi

Glad you got it worked out

14ga8dJ6NGpiwQkNTXg7KzwozasfaXNfEU
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 29, 2012, 01:01:20 PM
 #23

Ahhhh.  MS Server requires the Certificate. Linux does not.  Good to know. It makes me think that Campbx is also hosted on an MS Server box as you said you could authenticate to the other exchanges but not to Campbx.  Glad you got it working!
unclemantis
Member
**
Offline Offline

Activity: 98
Merit: 10


(:firstbits => "1mantis")


View Profile
July 29, 2012, 02:03:44 PM
 #24

PHP on IIS? UGH! No wonder!

DOOD! Switch to Linux for ANYTHING OPEN SOURCE!

PHP, Ruby, Rails, ASP, JavaScript, SQL
20+ years experience w/ Internet Technologies
Bitcoin OTC | GPG Public Key                                                                               thoughts?
scribe
Sr. Member
****
Offline Offline

Activity: 295
Merit: 250



View Profile WWW
July 29, 2012, 03:06:06 PM
 #25

Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  

Awesome - my 'tweak stuff til it does something different' approach works again... PM'd.

Now just got to figure out why php on osx hates anything https.

blocknois.es Bitcoin music label. ~ New release: This Is Art

Read: Bitcoin Life | Wear: FUTUREECONOMY
unclemantis
Member
**
Offline Offline

Activity: 98
Merit: 10


(:firstbits => "1mantis")


View Profile
July 29, 2012, 03:57:55 PM
 #26

Try using different SSL versions:

Code:
curl_setopt($curl, CURLOPT_SSLVERSION,3); // or try setting to 2


Bingo!  That did the trick.  


Thanks to everybody for your help.  scribe, can you please send or post your address for the 5BTC bounty?  Also, to BCB, gweedo, unfinishe, and drakahn, please send or post your address so I can send you a small donation for helping out.  

Awesome - my 'tweak stuff til it does something different' approach works again... PM'd.

Now just got to figure out why php on osx hates anything https.

Saint Jobs needs to spy on you. He can't spy on your through https Tongue

PHP, Ruby, Rails, ASP, JavaScript, SQL
20+ years experience w/ Internet Technologies
Bitcoin OTC | GPG Public Key                                                                               thoughts?
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 29, 2012, 07:24:50 PM
 #27

Yeah, I agree.  Linux is a good system and much better for running PHP.  I have a few thousand lines of code in classic asp so the migration has been happening slowly but surely. 

Thanks again for everybody's help.  The bounty and most of the donations have been sent.  BCB, I got a 2BTC donation coming your way if you're interested (I don't see an address in your sig).
BCB
CTG
VIP
Legendary
*
Offline Offline

Activity: 1078
Merit: 1002


BCJ


View Profile
July 29, 2012, 07:44:57 PM
 #28

Yeah, I agree.  Linux is a good system and much better for running PHP.  I have a few thousand lines of code in classic asp so the migration has been happening slowly but surely. 

Thanks again for everybody's help.  The bounty and most of the donations have been sent.  BCB, I got a 2BTC donation coming your way if you're interested (I don't see an address in your sig).

I appreciate that but I didn't solve the problem.  Happy to help you out.

Put the 2BTC towards a new linux box! Wink

Thanks!
CA Coins (OP)
Donator
Sr. Member
*
Offline Offline

Activity: 305
Merit: 250


View Profile
July 29, 2012, 08:14:14 PM
 #29

Cool dude.  Thanks for your help!
scribe
Sr. Member
****
Offline Offline

Activity: 295
Merit: 250



View Profile WWW
July 29, 2012, 08:48:44 PM
 #30

Thanks for the donation, CA - I'll keep it away from satoshidice I think Smiley I do a fair bit of dev work on Windows Server and then deploy to a Linux box, so I'll keep an eye out for this one in future...

Now just got to figure out why php on osx hates anything https.

Saint Jobs needs to spy on you. He can't spy on your through https Tongue

Pretty sure the big bearded dude in the sky could pull a MITM attack if he wanted to. Does God have root?

blocknois.es Bitcoin music label. ~ New release: This Is Art

Read: Bitcoin Life | Wear: FUTUREECONOMY
Pages: 1 2 [All]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!