# Required package requests: `pip install requests`
import json
import base64
import requests
# Using of Client Credentials authorization flow.
# Insert your client credentials received in welcome email.
client_id = "your_client_id"
client_secret = "your_client_secret"
identity_url = "https://id.livevol.com/connect/token"
api_url = "https://api.livevol.com/v1/delayed/allaccess/market/underlying-quotes?symbols=AAPL&date=2019-01-18"
authorization_token = base64.b64encode((client_id + ':' + client_secret).encode())
headers = {"Authorization": "Basic " + authorization_token.decode('ascii')}
payload = {"grant_type": "client_credentials"}
# Requesting access token
token_data = requests.post(identity_url, data=payload, headers=headers)
if token_data.status_code == 200:
access_token = token_data.json()['access_token']
if len(access_token) > 0:
print("Authenticated successfully")
# Requesting data from API
result = requests.get(api_url, headers={"Authorization": "Bearer " + access_token})
print(result.json())
else:
print("Authentication failed")
// Required packages: Newtonsoft.Json
// Using of Client Credentials authorization flow.
// Insert your client credentials received in welcome email.
var clientId = "your_client_id";
var clientSecret = "your_client_secret";
var identityUrl = "https://id.livevol.com/connect/token";
var apiUrl = "https://api.livevol.com/v1/delayed/allaccess/market/underlying-quotes?symbols=AAPL&date=2019-01-18";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}")));
var response = httpClient.PostAsync(identityUrl,
new FormUrlEncodedContent(
new Dictionary<string, string>()
{
{ "grant_type", "client_credentials"}
})).GetAwaiter().GetResult();
response.EnsureSuccessStatusCode();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer", JObject.Parse(response.Content.ReadAsStringAsync().GetAwaiter().GetResult()).Value<string>("access_token"));
var data = httpClient.GetStringAsync(apiUrl).GetAwaiter().GetResult();
Console.WriteLine(data);
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
// Using of Client Credentials authorization flow.
// Insert your client credentials received in welcome email.
var clientId = "your_client_id";
var clientSecret = "your_client_secret";
var identityUrl = "https://id.livevol.com/connect/token";
var apiUrl = "https://api.livevol.com/v1/delayed/allaccess/market/underlying-quotes?symbols=AAPL&date=2019-01-18"
// Requesting access token
function getAccesToken(url, client_id, client_secret) {
return $.ajax({
method: "POST",
url: url,
headers: {
Authorization: "Basic " + btoa(client_id + ':' + client_secret)
},
data: {
grant_type: "client_credentials"
}
});
}
// Requesting data from API
function callApi(url, access_token) {
return $.ajax({
method: "GET",
url: url,
headers: {
Authorization: "Bearer " + access_token
}
});
}
function show(mes) { alert(JSON.stringify(mes, null, ' ')) }
function showError(error) { show(error) }
getAccesToken(identityUrl, clientId, clientSecret)
.done(function (result) {
callApi(apiUrl, result.access_token)
.done(function (result) {
show(result);
})
.fail(showError)
})
.fail(showError)
</script>
// <dependencies>
// <dependency>
// <groupId>org.apache.httpcomponents</groupId>
// <artifactId>httpclient</artifactId>
// <version>4.5.12</version>
// </dependency>
// <dependency>
// <artifactId>json-simple</artifactId>
// <groupId>com.googlecode.json-simple</groupId>
// <version>1.1.1</version>
// </dependency>
// </dependencies>
// Using of Client Credentials authorization flow.
// Insert your client credentials received in welcome email.
String clientId = "your_client_id";
String clientSecret = "your_client_secret";
String identityUrl = "https://id.livevol.com/connect/token";
String apiUrl = "https://api.livevol.com/v1/delayed/allaccess/market/underlying-quotes?symbols=AAPL&date=2019-01-18";
// Requesting access token
String authorizationToken = Base64.encodeBase64String((clientId + ":" + clientSecret).getBytes(StandardCharsets.UTF_8));
CloseableHttpClient httpclient = HttpClients.custom().build();
HttpPost httpPost = new HttpPost(identityUrl);
httpPost.addHeader("Authorization", "Basic " + authorizationToken);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
httpPost.setEntity(new UrlEncodedFormEntity(postParameters, StandardCharsets.UTF_8));
CloseableHttpResponse response = httpclient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
JSONObject object = (JSONObject) new JSONParser().parse(EntityUtils.toString(response.getEntity()));
String accessToken = (String) object.get("access_token");
System.out.println("Authenticated successfully");
// Requesting data from API
httpclient = HttpClients.custom().build();
HttpGet httpGet = new HttpGet(apiUrl);
httpGet.addHeader("Authorization", "Bearer " + accessToken);
response = httpclient.execute(httpGet);
System.out.println(EntityUtils.toString(response.getEntity()));
} else {
System.out.println("Authentication failed");
}
require(RCurl)
require(httr)
# Enter your client credentials
client_id <- 'enter your client id'
client_secret <- 'enter your client secret'
encoded_credentials <- base64Encode(paste(client_id, ':', client_secret, sep=''))
# Request access token
get_token <- POST('https://id.livevol.com/connect/token', body='grant_type=client_credentials', add_headers(Authorization=paste('Basic ', encoded_credentials, sep='')))
content(get_token)
if (get_token$status_code == 200) {
print('Authentication successful')
parse_response <- content(get_token, as = 'parsed')
access_token <- parse_response['access_token']
response <- GET('https://api.livevol.com/v1/delayed/allaccess/market/underlying-quotes?date=2021-08-16&symbols=AAPL', add_headers(Authorization=paste('Bearer ', access_token, sep='')))
content(response)
} else {
print('Authentication failed')
}