How to use BlockChain API?

4

1

I am a complete noob to PHP. But I just wanted to know how can you use the BlockChain API to get your wallet balance. I tried but could get no result. I do not even know how to print it. Please help. This is my current code :-

    <?php

    $guid="xxxxxxxxx";
    $main_password="xxxxxxxxx";

    $json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed->message;

    ?>

And what exactly is the guid? Is it the wallet identifier?

rahulgarg12342

Posted 2014-07-18T19:12:21.723

Reputation: 237

Answers

4

Your code is close to what you need:

<?php

$guid="xxxxxxxxx";
$main_password="xxxxxxxxx";

$json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

$json_data = file_get_contents($json_url);

$json_feed = json_decode($json_data);

$balance = $json_feed->balance;

echo $balance;
?>

The response looks like this (Wallet Balance in Satoshi):

{ "balance": 1000}

So you need to fetch the balance object not the message one. Then add an echo to print out the balance.

Dennis Kriechel

Posted 2014-07-18T19:12:21.723

Reputation: 1 603

balance; echo $balance; ?> this is the result I got. Don't know why.rahulgarg12342 2014-07-18T19:24:04.727

just tested it with my own wallet it worked perfectly fine, maybe your put in the wrong credentialsDennis Kriechel 2014-07-18T19:27:25.773

is the guid the wallet identifier?rahulgarg12342 2014-07-18T19:28:11.040

yes its is, maybe you missed out a semicolon or an php tag, seems like an syntax error in your php maybe try to copy paste againDennis Kriechel 2014-07-18T19:28:19.453

ahh got it. The 2 factor auth was messing it up. Figured it out. Thanks. Just a little curious. How could I modify this to be performed after a certain time interval?rahulgarg12342 2014-07-18T19:34:01.960

@rahulgarg12342 How did you bypass the 2 factor authenticator? I am using the block chain api to do exactly the same thing, it is working but for 2 factor authenticator enabled wallets I am getting the error. How do I deal with that?Criesto 2014-09-04T08:23:38.940