Bitcoin Forum
November 10, 2024, 01:07:36 PM *
News: Latest Bitcoin Core release: 28.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 3191 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.
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?
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!