|
Gifted (OP)
|
|
June 13, 2016, 11:27:12 PM |
|
I am still trying to fix this..i get this error {"error_description": "You are not allowed", "error_code": 1} Here is the test page-----> http://www.bitcoinfaucetexchange.com/Balance-non-Xapo-Faucet-Users.phpHere is what i got so far <?php if(isset($_POST['checkBalance'])){ $addyBalance = trim($_POST['addyBalance']); if(empty($addyBalance)){ $output = "Please enter an address"; } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/addresses/".$addyBalance); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer 5a546edd-ad72-49e0-****-****64c59c80" )); $response = curl_exec($ch); //$output = "Balance: ".$response["accrued_balance"]; } print_r($response); }
?> <html> <form method="post"> Address: <input type="text" name="addyBalance"><br> <input type="submit" value="Check Balance" name="checkBalance"> </form> </html>
|
|
|
|
icanscript
|
|
June 14, 2016, 12:04:12 AM |
|
I am still trying to fix this..i get this error {"error_description": "You are not allowed", "error_code": 1} Here is the test page-----> http://www.bitcoinfaucetexchange.com/Balance-non-Xapo-Faucet-Users.phpHere is what i got so far <?php if(isset($_POST['checkBalance'])){ $addyBalance = trim($_POST['addyBalance']); if(empty($addyBalance)){ $output = "Please enter an address"; } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/addresses/".$addyBalance); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer 5a546edd-ad72-49e0-****-****64c59c80" )); $response = curl_exec($ch); //$output = "Balance: ".$response["accrued_balance"]; } print_r($response); }
?> <html> <form method="post"> Address: <input type="text" name="addyBalance"><br> <input type="submit" value="Check Balance" name="checkBalance"> </form> </html> The response should be 200 with a json object. That is a XAPO error code they are sending back, ensure API is setup on your account.
|
|
|
|
Gifted (OP)
|
|
June 14, 2016, 01:51:11 AM |
|
I am still trying to fix this..i get this error {"error_description": "You are not allowed", "error_code": 1} Here is the test page-----> http://www.bitcoinfaucetexchange.com/Balance-non-Xapo-Faucet-Users.phpHere is what i got so far <?php if(isset($_POST['checkBalance'])){ $addyBalance = trim($_POST['addyBalance']); if(empty($addyBalance)){ $output = "Please enter an address"; } else { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/addresses/".$addyBalance); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer 5a546edd-ad72-49e0-****-****64c59c80" )); $response = curl_exec($ch); //$output = "Balance: ".$response["accrued_balance"]; } print_r($response); }
?> <html> <form method="post"> Address: <input type="text" name="addyBalance"><br> <input type="submit" value="Check Balance" name="checkBalance"> </form> </html> The response should be 200 with a json object. That is a XAPO error code they are sending back, ensure API is setup on your account. I wrote to Xapo... lets see what they say.
|
|
|
|
icanscript
|
|
June 14, 2016, 10:22:04 AM |
|
Right, lets start from scratch....
What are you actually trying to achieve?
Does it need to include XAPO or is this just Bitcoin in general?
I have had a look at the API and it requires you to create an app and request an oauth token. was this done?
|
|
|
|
graphicalx
Member
Offline
Activity: 87
Merit: 10
Need logo design, banner design? PM me!
|
|
June 14, 2016, 08:57:36 PM |
|
Hey Gifted, I had PMed you
|
fund my procrastination: 1Hf1XG5cBnuFTxBVXUfUnK5hWLSBENqwnM [QR]
|
|
|
Gifted (OP)
|
|
June 14, 2016, 10:42:54 PM Last edit: June 16, 2016, 04:37:30 PM by Gifted |
|
Right, lets start from scratch....
What are you actually trying to achieve?
Does it need to include XAPO or is this just Bitcoin in general?
I have had a look at the API and it requires you to create an app and request an oauth token. was this done?
yes i did, this is the token in the code i wrote "Authorization: Bearer 5a**6edd-ad72-49e0-****-****64c59c80" I want to make a balance for my faucet here http://www.bitcoinfaucetexchange.comI would like it so they can put their email or BTC address in box and if Xapo doesn't recognize as a Xapo account it will show there balance and if it is a Xapo account it will be just zero because payments are instant. (reason is, Xapo holds all payments of bits until minimum value is 0.00005430 then sends) Just like it says in the API here http://docs.xapo.apiary.io/#reference/deposit-addresses You can see how http://moonbit.co.in did it
|
|
|
|
icanscript
|
|
June 15, 2016, 06:22:51 AM Last edit: June 15, 2016, 06:33:58 AM by icanscript |
|
Okay I have this working fine. The bearer tokens only last for 3600 Seconds (1 hour). not sure how many you can request, API doesn't seem to mention this. It may be we need to just auth one token and not allow another token to be used until the time is up. So now this code requests a new token everytime there is a request. New File functions.php <?php
function GetAuthToken() { $sYourRedirectUri = ""; $sAPPID = ""; $sAPPSecret = ""; $sPostFields = "client_credentials&redirect_uri=" . $sYourRedirectUri; $sAuthCode = base64_encode($sAPPID . ":" . $sAPPSecret); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=" . $sPostFields); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic " . $sAuthCode )); $response = curl_exec($ch); curl_close($ch); return $response; }
?>
Example Output: {"token_type":"bearer","access_token":"87478519-c4af-495b-9120-77169c27771d","expires_in":3600}
Main Code <?php
require_once("functions.php");
$sToken = json_decode(GetAuthToken());
if(isset($_POST['addyBalance'])){
$addyBalance = $_POST['addyBalance'];
if(empty($addyBalance)) { echo "No Address Entered"; die(); }
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/addresses/" . $addyBalance); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer " . $sToken->access_token )); $response = curl_exec($ch); print_r($response); }
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST"> Address: <input type="text" name="addyBalance"><br> <input type="submit" value="Check Balance"> </form>
Example Output: (random address from blockchain.info) {"address": "1NuS88r6WPwkcCF5umiqz36mvxgnZWgV5W", "accrued_balance": "0.00000000", "payment_threshold": "0.00005430"}
|
|
|
|
alfaboy23
|
|
June 23, 2016, 07:38:07 AM Last edit: June 28, 2016, 02:56:10 AM by alfaboy23 |
|
This is my contribution on Xapo API: Showing the faucet balance 1. Save the PHP code to a PHP file, change the YOUR_REDIRECT_URI, YOUR_APP_ID and YOUR_SECRET_KEY with your own data and put the file anywhere you like in your root of your domain, or where you config.php is (Ex: public_html/MyXapoBalance.php) PHP code : <?php function get_bal(){ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&redirect_uri=YOUR_REDIRECT_URI");
$basic_token = base64_encode("YOUR_APP_ID:YOUR_SECRET_KEY"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic ".$basic_token ));
$respons = curl_exec($ch); curl_close($ch); $json = json_decode($respons);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/accounts/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: Bearer ".$json->{'access_token'} ));
$respons = curl_exec($ch); curl_close($ch);
//var_dump($respons);
$bal = json_decode($respons, true);
echo $bal[0]['available_balance'] * 100000000;
}
?>
2. Put this in the index.php in the root of your domain, or where you config.php is (Ex: public_html/index.php) require 'MyXapoBalance.php';
3. Then, put this somewhere in style/template/index.php (Ex: I put mine below the rewards description, see screenshot above) <div><p class="alert alert-info">Balance: <?php echo get_bal(); ?></p></div>
NOTES:You have to use a Xapo account with only one wallet or it will randomly show the balance of the active wallets from your account. By the way, this thread should be in the development section.
|
|
|
|
Gifted (OP)
|
|
June 23, 2016, 11:32:50 PM Last edit: June 23, 2016, 11:59:18 PM by Gifted |
|
This is my contribution on Xapo API: Showing the faucet balance PHP code: <?php function get_bal(){ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&redirect_uri=YOUR_REDIRECT_URI");
$basic_token = base64_encode("YOUR_APP_ID:YOUR_SECRET_KEY"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic ".$basic_token ));
$respons = curl_exec($ch); curl_close($ch); $json = json_decode($respons);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/accounts/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: Bearer ".$json->{'access_token'} ));
$respons = curl_exec($ch); curl_close($ch);
//var_dump($respons);
$bal = json_decode($respons, true);
echo $bal[0]['available_balance'] * 100000000;
}
?>
Then, put this somewhere in index.php <div><p class="alert alert-info">Balance: <?php echo get_bal(); ?></p></div>
By the way, this thread should be in the development section. nice !!!! but something is not right.... i have more then 5000 satoshi in account where do i put the php? i think i fixed
|
|
|
|
alfaboy23
|
|
June 24, 2016, 12:09:50 AM |
|
-snip-
nice !!!! but something is not right.... i have more then 5000 satoshi in account where do i put the php? i think i fixed
I've put the code in a separate PHP file and call (require) it in index.php in root.
|
|
|
|
Gifted (OP)
|
|
June 24, 2016, 01:14:22 AM |
|
-snip-
nice !!!! but something is not right.... i have more then 5000 satoshi in account where do i put the php? i think i fixed
I've put the code in a separate PHP file and call (require) it in index.php in root. ahh ok
|
|
|
|
Gifted (OP)
|
|
June 27, 2016, 10:33:29 PM |
|
This is my contribution on Xapo API: Showing the faucet balance PHP code: <?php function get_bal(){ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&redirect_uri=YOUR_REDIRECT_URI");
$basic_token = base64_encode("YOUR_APP_ID:YOUR_SECRET_KEY"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic ".$basic_token ));
$respons = curl_exec($ch); curl_close($ch); $json = json_decode($respons);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/accounts/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Authorization: Bearer ".$json->{'access_token'} ));
$respons = curl_exec($ch); curl_close($ch);
//var_dump($respons);
$bal = json_decode($respons, true);
echo $bal[0]['available_balance'] * 100000000;
}
?>
Then, put this somewhere in index.php <div><p class="alert alert-info">Balance: <?php echo get_bal(); ?></p></div>
By the way, this thread should be in the development section. This si not working for me... i have bow written to Fabian for help.. maybe they had to open your scopes for this. AlfaBoy.. Maybe you show write complete instructions here for novice php programmers because even i cant get what you said.
|
|
|
|
|
Gifted (OP)
|
|
June 28, 2016, 09:13:16 PM |
|
yes, now it is working thank you !
|
|
|
|
5ub_zer0
|
|
July 14, 2016, 06:47:10 AM |
|
Okay I have this working fine. The bearer tokens only last for 3600 Seconds (1 hour). not sure how many you can request, API doesn't seem to mention this. It may be we need to just auth one token and not allow another token to be used until the time is up. So now this code requests a new token everytime there is a request. New File functions.php <?php
function GetAuthToken() { $sYourRedirectUri = ""; $sAPPID = ""; $sAPPSecret = ""; $sPostFields = "client_credentials&redirect_uri=" . $sYourRedirectUri; $sAuthCode = base64_encode($sAPPID . ":" . $sAPPSecret); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=" . $sPostFields); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic " . $sAuthCode )); $response = curl_exec($ch); curl_close($ch); return $response; }
?>
Example Output: {"token_type":"bearer","access_token":"87478519-c4af-495b-9120-77169c27771d","expires_in":3600}
Main Code <?php
require_once("functions.php");
$sToken = json_decode(GetAuthToken());
if(isset($_POST['addyBalance'])){
$addyBalance = $_POST['addyBalance'];
if(empty($addyBalance)) { echo "No Address Entered"; die(); }
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://v2.api.xapo.com/addresses/" . $addyBalance); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer " . $sToken->access_token )); $response = curl_exec($ch); print_r($response); }
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST"> Address: <input type="text" name="addyBalance"><br> <input type="submit" value="Check Balance"> </form>
Example Output: (random address from blockchain.info) {"address": "1NuS88r6WPwkcCF5umiqz36mvxgnZWgV5W", "accrued_balance": "0.00000000", "payment_threshold": "0.00005430"}
W0W cool now i have two questions .. the first maybe very simple the second more a challenge ..(sorry i have no programming skill for do it self) 1.) How can i make the output {"address": "1NuS88r6WPwkcCF5umiqz36mvxgnZWgV5W", "accrued_balance": "0.00000000", "payment_threshold": "0.00005430"}
more beautyful .. maybe that i can insered in html/php with a call like: your current = $balance and the = $threshold ? (accrued_balance -> $balance | payment_threshold -> $threshold) 2.) The XAPO API allows to set the Threshold example code My idea is that when a visitor come to my faucet and enter his BTC address, press the claim button the script check if the input string does not include a @ so he is a non XAPO user ..than the script uses the string (BTC Address) to set the threshold to a predefined Amount (inex 0.000010000) and update the balance script you written above. I know that its difficult to read my english .. sorry for that - but i hope you know what i mean
|
|
|
|
icanscript
|
|
July 14, 2016, 09:23:35 AM |
|
Hi, 1) <?php
$jsonresponse = json_decode($response);
echo 'your current balance = ' . $jsonresponse->accrued_balance . ' and the threshold = ' . $jsonresponse->payment_threshold;
?> 2) From what I remember it automatic, but il look into it for you.
|
|
|
|
Gifted (OP)
|
|
July 14, 2016, 01:19:49 PM |
|
Hi, glad to see this thread moving. @icanscript i would like to send you some BTC even though it was made before you completed here for your time. Also what he is saying is a great idea as far as setting threshold automatic or even to let them change it themselves . What i'm trying to figure out is how to have a balance for non Xapo users on the front page and is automatically checked when claimed instead of what i did here. http://www.bitcoinfaucetexchange.com/Balance.phpThough the page is a better advertising platform....would be more better in the front page.
|
|
|
|
icanscript
|
|
July 14, 2016, 01:45:48 PM |
|
Hi, glad to see this thread moving. @icanscript i would like to send you some BTC even though it was made before you completed here for your time. Also what he is saying is a great idea as far as setting threshold automatic or even to let them change it themselves . What i'm trying to figure out is how to have a balance for non Xapo users on the front page and is automatically checked when claimed instead of what i did here. http://www.bitcoinfaucetexchange.com/Balance.phpThough the page is a better advertising platform....would be more better in the front page. Do you mean. A user who uses the faucet who IS NOT a Xapo user also has a balance? so when they reach a certain amount they can then withdraw? and cant withdraw until they reach that amount? That would work slightly differently, as we would need to store their addresses value, which we could do in a db like mysql, or a flatdb file. My address is 1Dt5KPqWQ18L4EQ3DWzriHLnKfDg45uTx7 , thanks for any tips. Regards, icanscript
|
|
|
|
Gifted (OP)
|
|
July 14, 2016, 02:54:18 PM |
|
Hi, glad to see this thread moving. @icanscript i would like to send you some BTC even though it was made before you completed here for your time. Also what he is saying is a great idea as far as setting threshold automatic or even to let them change it themselves . What i'm trying to figure out is how to have a balance for non Xapo users on the front page and is automatically checked when claimed instead of what i did here. http://www.bitcoinfaucetexchange.com/Balance.phpThough the page is a better advertising platform....would be more better in the front page. Do you mean. A user who uses the faucet who IS NOT a Xapo user also has a balance? so when they reach a certain amount they can then withdraw? and cant withdraw until they reach that amount? That would work slightly differently, as we would need to store their addresses value, which we could do in a db like mysql, or a flatdb file. My address is 1Dt5KPqWQ18L4EQ3DWzriHLnKfDg45uTx7 , thanks for any tips. Regards, icanscript No, the account is held by Xapo and will show the balance if API is called but if its a email or a Xapo account BTC address the counter is always zero. subzero is talking about automatic setting threshold for 10,000 but for me it would be cool just to call the API automatic when claimed...so there is also an api call to change the threshold for any non- Xapo address.so no need for SQL table. I sent you a tip https://blockchain.info/address/1Dt5KPqWQ18L4EQ3DWzriHLnKfDg45uTx7
|
|
|
|
|