$ch = curl_init();
$headers = array(
'Authorization: Token {token}',
'Content-Type: application/json',
);
$api_endpoint = 'http://api.paperquotes.com/apiv1/quotes/?tags=love&limit=5';
curl_setopt($ch, CURLOPT_URL, $api_endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
echo $response;
Make sure you have Jquery included:
$.ajax({
type : "GET",
url : "https://api.paperquotes.com/apiv1/quotes/",
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Token {token}');},
success : function(result) {
console.log(result.results);
},
error : function(result) {
//handle the error
}
});
See full client documentation here:
https://github.com/markus-perl/gender-api-client-npm
import requests, json
PAPERQUOTES_API_ENDPOINT = 'http://api.paperquotes.com/apiv1/quotes?tags=love&limit=5'
TOKEN = '{your_token}'
response = requests.get(PAPERQUOTES_API_ENDPOINT, headers={'Authorization': 'TOKEN {}'.format(TOKEN)})
if response.ok:
quotes = json.loads(response.text).get('results')
for quote in quotes:
print quote.get('quote')
print quote.get('author')
print quote.get('tags')
using System;
using System.IO;
using System.Net;
namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main()
{
// Create a request for the URL.
WebRequest request = WebRequest.Create(
"http://api.paperquotes.com/apiv1/quotes/?curated=1&tags=love,life");
request.Headers.Add("Authorization", "Token {token}");
// If required by the server, set the credentials.
//request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
// Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
// The using block ensures the stream is automatically closed.
using (Stream dataStream = response.GetResponseStream())
{
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
}
// Close the response.
response.Close();
}
}
}