Pages:
Author

Topic: Looking for a PHP /HTML/Xapo-API Person ! - page 2. (Read 2247 times)

hero member
Activity: 504
Merit: 501
Here is an example of someone else doing it. http://moonbit.co.in

As you can see there is a balance up top in a counter. If your a Xapo client the API knows and leaves at zero but if not the API shows the balance automatic.
Its basically the same  API calls but using the input box for address and the claim button to call the API to check/chnage threshold and post the balance if an Xapo acccount.  Here is the faucet script we are all using. https://github.com/destinybogan/Faucet-Builder
hero member
Activity: 504
Merit: 501
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.php

Though 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   Wink
hero member
Activity: 686
Merit: 502
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.php

Though 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
hero member
Activity: 504
Merit: 501
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.php

Though the page is a better advertising platform....would be more better in the front page.
hero member
Activity: 686
Merit: 502
Hi,

1)

Code:

$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.



full member
Activity: 238
Merit: 100
hero member
Activity: 504
Merit: 501
Ok, I edited my comment above.
I put a complete instruction.

https://bitcointalksearch.org/topic/m.15329533
yes, now it is working  thank you !
hero member
Activity: 546
Merit: 500
Ok, I edited my comment above.
I put a complete instruction.

https://bitcointalksearch.org/topic/m.15329533
hero member
Activity: 504
Merit: 501
hero member
Activity: 504
Merit: 501
-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
hero member
Activity: 546
Merit: 500
-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.
hero member
Activity: 504
Merit: 501
hero member
Activity: 546
Merit: 500
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 :
Code:
function get_bal(){
$ch curl_init();

curl_setopt($chCURLOPT_URL"https://v2.api.xapo.com/oauth2/token");
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($chCURLOPT_HEADERFALSE);

curl_setopt($chCURLOPT_POSTTRUE);

curl_setopt($chCURLOPT_POSTFIELDS"grant_type=client_credentials&redirect_uri=YOUR_REDIRECT_URI");

$basic_token base64_encode("YOUR_APP_ID:YOUR_SECRET_KEY");
curl_setopt($chCURLOPT_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($chCURLOPT_URL"https://v2.api.xapo.com/accounts/");
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($chCURLOPT_HEADERFALSE);
curl_setopt($chCURLOPT_HTTPGETTRUE);

curl_setopt($chCURLOPT_HTTPHEADER, array(
  
"Content-Type: application/json",
  
"Authorization: Bearer ".$json->{'access_token'}
));

$respons curl_exec($ch);
curl_close($ch);

//var_dump($respons);

$bal json_decode($responstrue);

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)
Code:
 
require 'MyXapoBalance.php';

3. Then, put this somewhere in style/template/index.php (Ex: I put mine below the rewards description, see screenshot above)
Code:

Balance: echo get_bal(); ?>




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.

hero member
Activity: 686
Merit: 502
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

Code:

function GetAuthToken() {
    
    
$sYourRedirectUri "";
    
$sAPPID "";
    
$sAPPSecret "";
    
    
$sPostFields "client_credentials&redirect_uri=" $sYourRedirectUri;
    
$sAuthCode base64_encode($sAPPID ":" $sAPPSecret);
    
    
$ch curl_init();
    
    
curl_setopt($chCURLOPT_URL"https://v2.api.xapo.com/oauth2/token");
    
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
    
curl_setopt($chCURLOPT_HEADERFALSE);
    
    
curl_setopt($chCURLOPT_POSTTRUE);
    
    
curl_setopt($chCURLOPT_POSTFIELDS"grant_type=" $sPostFields);
    
    
curl_setopt($chCURLOPT_HTTPHEADER, array(
      
"Content-Type: application/x-www-form-urlencoded",
      
"Authorization: Basic " $sAuthCode
    
));
    
    
$response curl_exec($ch);
    
curl_close($ch);
    
    return 
$response;
}

?>


Example Output:

Code:
{"token_type":"bearer","access_token":"87478519-c4af-495b-9120-77169c27771d","expires_in":3600}

Main Code

Code:

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($chCURLOPT_URL"https://v2.api.xapo.com/addresses/" $addyBalance);
   
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
   
curl_setopt($chCURLOPT_HEADERFALSE);
   
curl_setopt($chCURLOPT_HTTPHEADER, array(
     
"Authorization: Bearer " $sToken->access_token
   
));
   
$response curl_exec($ch);
  
  
print_r($response);
}

?>


  
echo htmlentities($_SERVER['PHP_SELF']);?>" method="POST">
      Address:

      
  



Example Output: (random address from blockchain.info)

Code:
{"address": "1NuS88r6WPwkcCF5umiqz36mvxgnZWgV5W", "accrued_balance": "0.00000000", "payment_threshold": "0.00005430"}

hero member
Activity: 504
Merit: 501
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.com
I 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
member
Activity: 87
Merit: 10
Need logo design, banner design? PM me!
Hey Gifted, I had PMed you
hero member
Activity: 686
Merit: 502
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?
hero member
Activity: 504
Merit: 501
hero member
Activity: 686
Merit: 502
hero member
Activity: 504
Merit: 501
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.php

Here is what i got so far

 
Code:
if(isset($_POST['checkBalance'])){
$addyBalance trim($_POST['addyBalance']);
  if(empty(
$addyBalance)){
   
$output "Please enter an address";
  } else {
   
$ch curl_init();
   
curl_setopt($chCURLOPT_URL"https://v2.api.xapo.com/addresses/".$addyBalance);
   
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
   
curl_setopt($chCURLOPT_HEADERFALSE);
   
curl_setopt($chCURLOPT_HTTPHEADER, array(
     
"Authorization: Bearer 5a546edd-ad72-49e0-****-****64c59c80"
   
));
   
$response curl_exec($ch);
   
//$output = "Balance: ".$response["accrued_balance"];
  
}
  
print_r($response);
}

?>



Address:



Pages:
Jump to: