I am new to integrating bitcoin API to my PHP page, I have created a bitcoin account with luno, I have created API Key.
I have been given this url to get balance using my generated API Key:
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/balance
Can anybody help with a proper example on how I can use my API with this given url to display my wallet balance on a PHP page?
The easiest way I know to convert curl commands to executable PHP code is to use this site: https://incarnate.github.io/curl-to-php/
Just add your curl command:
curl -u keyid:keysecret https://api.mybitx.com/api/1/balance
to the textbox that says "Paste curl here". Then take the PHP that is output and integrate it into your app.
You can use the PHP Requests library for an easy way to make HTTP Requests. Your curl command can be converted as follows:
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
// Use additional headers if necessary
$headers = array();
// Create authorization using key and secret.
$options = array('auth' => array('keyid', 'keysecret'));
// Create the GET request to the URL
$response = Requests::get('https://api.mybitx.com/api/1/balance', $headers, $options);
// The result is available in $response
?>
Related
I have setup a webhook in shopify via settings > notifications > webhooks and entered a heroku app URL. My heroku app is in php and I run the verification function found here: https://shopify.dev/tutorials/manage-webhooks and when I open my app I get a blank response. I am not sure if this is something I am doing wrong on my heroku app, or if I am missing something. The goal here is to grab the json data after the event I have selected is ran, then to send that data to via third party api. But to start I just want to be able to verify that my heroku app is receiving the payload. Is there more I need to add to my php file in order to verify? (php noob here). Below is the code I am running in my php file, and yes I am using my shared secret found in the webhooks section.
<?php
define('SHOPIFY_APP_SECRET', 'my_shared_secret');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result
?>
If I am not mistaken you cannot test webhooks that way as the admin does not use your API key as it has no idea who you are when in the admin. So if you have a heroku App and it has an API key, use that API key to first off establish the webhook, verify you created it with the API, and then sit around and test your actual endpoint with Shopify Admin itself. That is how it works AFAIK.
The other verification in the admin is mickey mouse and meant to just throw data at any old endpoint with no validation.
I'm attempting to hit the PageSpeed Insights API as documented here https://developers.google.com/speed/docs/insights/v5/about with PHP and curl and am getting in return a response that looks like this:
{
'captchaResult' => "CAPTCHA_NEEDED"
}
My code to query the API looks like this:
$url = 'https://google.com';
$cmd = "curl -H 'Cache-Control: no-cache' https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=$url&key={MY_KEY}";
$result = json_decode(`$cmd`, true);
The documentation states "If you plan on using the API in an automated way and making multiple queries per second, you'll need an API key". I've created an API key in the developer's console, but am still getting the above result.
Ideally, I'd like to be able to make short bursts of 10-20 requests per second.
I have two questions:
Is there any documentation available for rate limiting in the PageSpeed Insights API?
How do I satisfy the CAPTCHA_NEEDED requirement for this API?
You required to get the API key to proceed without captcha, via credentials page.
Then set up environment variable with key you got on previous step, for example:
MY_KEY=adasda5434sdsa234sasdd
set website url:
URL="https://EXAMPLE.com"
then you can use service from CLI:
curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url={$URL}&&key={$MY_KEY}
Also, you can use curl without variables:
curl https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://EXAMPLE.com&&key=adasda5434sdsa234sasdd
Documentation available.
I'm trying to get list of invoices for specific customer from Stripe using PHP.
Following is the code I'm using.
\Stripe\Stripe::setApiKey('STRIPE_SECRET_KEY');
$response = \Stripe\Invoice::all(array('customer' => 'CUSTOMER_TOKEN'));
But this returns empty array.
Instead, CURL command returns result
curl https://api.stripe.com/v1/invoices?customer=CUSTOMER_TOKEN -u STRIPE_SECRET_KEY
Any idea?
I'm using Stripe PHP library available from Github.
https://github.com/stripe/stripe-php
$response = \Stripe\Invoice::all(array('customer' => 'cus_id'));
You need to add customer id for specific customer.
I'm a php programmer but I'm new to APIs.
I would like to run a mysql query to get info from an XML document from madmimi.com.
documentation from madmimi.com says
GET http://madmimi.com/audience_lists/lists.xml will return the data I need. I've created a php file and connected to their API using
require(dirname(FILE) . '/MadMimi.class.php');
$mailer = new MadMimi('username', 'password');
but I don't understand how to use GET to connect to the URL and display the XML info?
What do I need to do?
All http api interaction is hidden to you behind their library. You can use it's methods to grab objects, like this to lists:
$mailer->Lists();
There is no complete documentation, but you can read raw code to search urls, described in API for finding appreciated methods.
You can use curl to get the response from the 3rd party api. Have a look at this answer:
https://stackoverflow.com/a/5159513/1369567
Based upon the code in answer given at that link, you may need to the code to match your request. E.g:
/* Script URL */
$url = 'http://madmimi.com/audience_lists/lists.xml';
/* $_GET Parameters to Send */
$params = array('username' => '*your api username*', 'password' => '*your api password*');
In the past, using Twitter API version 1, I used the following URL to get a JSON feed of all tweets with the hashtag "baseball":
http://search.twitter.com/search.json?q=%23baseball&result_type=recent
How do you achieve a similar result using API version 1.1? I'm using PHP as my server-side code, so not sure if I need to use it to authenticate and such?
Sample code would be extremely helpful. Thanks.
As you know, authenticated requests are now required, so there's a few things that you may need to take a look at first. The new 1.1 search, how to use hashtags, and authentication.
Twitter Search for 1.1
The new twitter search api docs can be found here. According to these docs:
https://api.twitter.com/1.1/search/tweets.json is the new resource URL to use for search.
Hashtag searches
You've got that part right! %23 decodes to a # character.
Authentication
OAuth is a lot more complex. It would help if you just used a library that just worked.
Here's a post a lot of people found useful to help you make authenticated requests to the 1.1 API. This includes a one-file include library to make requests like those you require.
Example
This example assumes you're using the above library and set up your keys etc. To make your request:
// Your specific requirements
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#baseball&result_type=recent';
// Perform the request
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
Yes, that's it. Apart from the little setting up you need to do (as my post explains), for your dev keys, that's everything you need to perform authenticated requests.
Response
The response is returned to you in JSON. From the overview:
API v1.1 will support JSON only. We've been hinting at this for some time now, first dropping XML support on the Streaming API and more recently on the trends API. We've chosen to throw our support behind the JSON format shared across the platform.
If you just want to test, you can do the follow:
Access the twitter dev console: https://dev.twitter.com/console
In Authentication put: OAuth 1, that will ask you to give permission from your twitter account.
Request URL put GET
In url: https://api.twitter.com/1.1/search/tweets.json?q=%23yourhashtag
After Send, in Request window, copy the Authorization value.
Now put it in your request header.
Go example:
func main() {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.twitter.com/1.1/search/tweets.json?q=%23golang", nil)
req.Header.Add("Authorization", `OAuth oauth_consumer_key=...`)
resp, _ := client.Do(req)
io.Copy(os.Stdout, resp.Body)
}
Here's a simple example in python using application-only auth using the requests API. Get keys by creating an app at https://apps.twitter.com/app/new.
api_key = ...
api_secret = ...
# https://dev.twitter.com/oauth/application-only
# The base64 stuff described there is the normal Basic Auth dance.
import requests
r = requests.post('https://api.twitter.com/oauth2/token',
auth=(api_key, api_secret),
headers={'Content-Type':
'application/x-www-form-urlencoded;charset=UTF-8'},
data='grant_type=client_credentials')
assert r.json()['token_type'] == 'bearer'
bearer = r.json()['access_token']
url = 'https://api.twitter.com/1.1/search/tweets.json?q=%23yourhashtag'
r = requests.get(url, headers={'Authorization': 'Bearer ' + bearer})
print r.json()