Bitcoin Forum
October 20, 2017, 09:43:19 PM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Help with blockchain.info JSON RPC API??  (Read 4104 times)
BiTCoinRC
Jr. Member
*
Offline Offline

Activity: 30



View Profile
May 09, 2013, 09:10:43 PM
 #1

Hi,

I have opened a blockchain.info wallet in the hope of using their JSON RPC API for a website project, and am trying to use code below to show the balance of the wallet on my website to test the water.

Code:
<?php

/* Configuration variables for the JSON-RPC server */
$rpc_host 'rpc.blockchain.info';
$rpc_port '80';
$rpc_user 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$rpc_pass 'PASSWORD';


require_once(
'jsonRPCClient.php');
$bc = new jsonRPCClient('http://' $rpc_user ':' $rpc_pass '@' $rpc_host ':' $rpc_port);

$balance $bc->getbalance();

?>

However I get these errors:

Code:
Warning: fopen(http://...@rpc.blockchain.info:80) [function.fopen]: failed to open stream: operation failed in /home/*****/public_html/*****/jsonRPCClient.php on line 132

Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX:PASSWORD@rpc.blockchain.info:80' in /home/a*****/public_html/*****/jsonRPCClient.php:140 Stack trace: #0 /home/*****/public_html/*****/index.php(18): jsonRPCClient->__call('getbalance', Array) #1 /home/*****/public_html/*****/index.php(18): jsonRPCClient->getbalance() #2 {main} thrown in /home/*****/public_html/*****/jsonRPCClient.php on line 140

Does anybody have any idea what I am doing wrong?

EDIT SOLVED: I was using a strong password with various symbols (*#; etc..) in for the blockchain wallet and it did not seem to like this.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1508535799
Hero Member
*
Offline Offline

Posts: 1508535799

View Profile Personal Message (Offline)

Ignore
1508535799
Reply with quote  #2

1508535799
Report to moderator
Abdussamad
Legendary
*
Offline Offline

Activity: 1526



View Profile WWW
May 10, 2013, 01:25:33 AM
 #2

Use https instead of http or your password is passed in plain text.

BiTCoinRC
Jr. Member
*
Offline Offline

Activity: 30



View Profile
May 10, 2013, 08:36:35 AM
 #3

Use https instead of http or your password is passed in plain text.

How do you do this? By buying an SSL cert for the domain and using port 443??

Sorry I have never used https when building websites before, thanks.
Abdussamad
Legendary
*
Offline Offline

Activity: 1526



View Profile WWW
May 10, 2013, 09:23:37 AM
 #4

I meant use https://rpc.blockchain... instead of http://rpc.block... in your call to the jsonrpc constructor.

BiTCoinRC
Jr. Member
*
Offline Offline

Activity: 30



View Profile
May 10, 2013, 09:49:01 AM
 #5

If I change the code and port to this:

Code:
<?php

/* Configuration variables for the JSON-RPC server */
$rpc_host 'rpc.blockchain.info';
$rpc_port '443';
$rpc_user 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$rpc_pass 'PASSWORD';


require_once(
'jsonRPCClient.php');
$bc = new jsonRPCClient('https://' $rpc_user ':' $rpc_pass '@' $rpc_host ':' $rpc_port);

$balance $bc->getbalance();

?>

It will not connect??
lexxus
Sr. Member
****
Offline Offline

Activity: 322


View Profile
May 10, 2013, 11:22:52 AM
 #6

If I change the code and port to this:

Code:
<?php

/* Configuration variables for the JSON-RPC server */
$rpc_host 'rpc.blockchain.info';
$rpc_port '443';
$rpc_user 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
$rpc_pass 'PASSWORD';


require_once(
'jsonRPCClient.php');
$bc = new jsonRPCClient('https://' $rpc_user ':' $rpc_pass '@' $rpc_host ':' $rpc_port);

$balance $bc->getbalance();

?>

It will not connect??

It should. You don't need to buy certificate in order to connect to HTTPS server. You need to buy it only if want to own a server with SSL support/
lexxus
Sr. Member
****
Offline Offline

Activity: 322


View Profile
May 10, 2013, 11:24:29 AM
 #7

You can use strong password with special symbools and spaces but you need to encode it before using as a part of URL. Use http://php.net/manual/en/function.urlencode.php on your URL and it will work fine. No need to use weaker password.
BiTCoinRC
Jr. Member
*
Offline Offline

Activity: 30



View Profile
May 10, 2013, 11:43:36 AM
 #8

In the documentation (https://blockchain.info/api/json_rpc_api) I see -rpcssl Set to use a secure connection (Recommended), how can I set this in the code above? Thanks for the info about url encode Smiley
lexxus
Sr. Member
****
Offline Offline

Activity: 322


View Profile
May 10, 2013, 12:02:27 PM
 #9

In the documentation (https://blockchain.info/api/json_rpc_api) I see -rpcssl Set to use a secure connection (Recommended), how can I set this in the code above? Thanks for the info about url encode Smiley

As far as I know, when you specify "https://" you should automatically connect with SSL enabled (I'm not a PHP programmer). You can check it by connecting to non-ssl site (e.g. you own local webserver) using "https://" prefix, if it gives error then it works fine.
BiTCoinRC
Jr. Member
*
Offline Offline

Activity: 30



View Profile
May 10, 2013, 05:30:59 PM
 #10

In the documentation (https://blockchain.info/api/json_rpc_api) I see -rpcssl Set to use a secure connection (Recommended), how can I set this in the code above? Thanks for the info about url encode Smiley

As far as I know, when you specify "https://" you should automatically connect with SSL enabled (I'm not a PHP programmer). You can check it by connecting to non-ssl site (e.g. you own local webserver) using "https://" prefix, if it gives error then it works fine.

Unfortunately doing this does not seem to work in this case.
Abdussamad
Legendary
*
Offline Offline

Activity: 1526



View Profile WWW
May 10, 2013, 10:54:34 PM
 #11

You need to install the openssl PHP extension. You can check whether you have it installed by running the following command on the linux command line:

Code:
php -m |grep openssl

If the above command displays nothing that means you don't have openssl installed.

How you install it depends on your linux distro.

Abdussamad
Legendary
*
Offline Offline

Activity: 1526



View Profile WWW
May 10, 2013, 10:57:25 PM
 #12

Also, FYI, blockchain.info has a second API called a merchants API. You can see it here:

http://blockchain.info/api/blockchain_wallet_api

Of course you still need openssl installed.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!