Authentication Using OAuth

What is OAuth?
An alternative way to communicate with Bigstock's API is through OAuth.  OAuth is an authentication protocol that allows users to approve an application to act on their behalf without sharing their password.  This method is more secure than normal API communication. Your account id and secret key are never directly passed in as URL parameters, all requests must be over SSL, and tokens expire after a short period of time.
 
How do I work with OAuth?
The easiest way to work with OAuth is through cURL. The first thing you'll need to do is request a token.
 
cURL
curl -u [account id]:[secret key] https://api.bigstockphoto.com/2/oauth2/token -d 'grant_type=client_credentials' 
 
PHP
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://api.bigstockphoto.com/2/oauth2/token');
curl_setopt($handle, CURLOPT_USERPWD, '[account id]:[secret key]');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('grant_type' => 'client_credentials'));
curl_exec($handle);
 
Response
{
"access_token" : "483b330847b35404f12f459a24c84224bfb996eb",
"expires_in" : 3600,
"token_type" : "Bearer",
"scope" : null
}
 
Armed with a token you can now make any request you'd like, passing in the token as an extra parameter. Just follow the same routes as referenced in the primary documentation, replacing the [account id] with 'oauth2'.
 
Here are a few examples:
 
cURL
curl https://api.bigstockphoto.com/2/oauth2/search?q=upper%20peninsula -d 'access_token=[access token]'

curl https://api.bigstockphoto.com/2/oauth2/categories -d 'access_token=[access token]'
 
PHP
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://api.bigstockphoto.com/2/oauth2/search?q=upper%20peninsula');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('access_token' => '[access token]'));
curl_exec($handle);

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://api.bigstockphoto.com/2/oauth2/categories');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('access_token' => '[access token]'));
curl_exec($handle);

Additional Resources
OAuth2 Bigstock API Client Library

Still have questions? Email us here
  • Was this article helpful?

Can’t find what you’re looking for?

1-855-272-5125 Monday-Friday, 9:00am-5:00pm EST