├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── examples ├── javascript-jquery └── v2.html └── php-curl ├── .rock.yml ├── README.md ├── index.php └── v2.php /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at open-source@shutterstock.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribute 2 | 3 | Please contribute! Here are some things that would be great: 4 | - [Open an issue!](https://github.com/shutterstock/api/issues/new) 5 | - Open a pull request! 6 | - Say hi! :wave: 7 | 8 | Please abide by the [code of conduct](CODE_OF_CONDUCT.md). 9 | 10 | For more on contributing at @Shutterstock, check out our [welcome repository](https://github.com/shutterstock/welcome). 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Shutterstock Images, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shutterstock API 2 | 3 | > Shutterstock API Clients and Examples 4 | 5 | This is a collection of resources for the Shutterstock API. 6 | 7 | * [Clients](#clients) 8 | * [Examples](#examples) 9 | * [Contribute](#contribute) 10 | * [License](#license) 11 | 12 | ## Clients 13 | 14 | These clients are not officially supported by Shutterstock. Feel free to [create a pull request](https://help.github.com/articles/using-pull-requests) with a link to your open source client. 15 | 16 | Node 17 | 18 | * [node-shutterstock](https://www.npmjs.com/package/shutterstock) (MIT) 19 | * [node-shutterstock-api](https://github.com/shutterstock/node-shutterstock-api) 20 | 21 | Perl 22 | 23 | * [WebService-Shutterstock](http://search.cpan.org/~bphillips/WebService-Shutterstock/) (GNU or Artistic License) 24 | 25 | PHP 26 | 27 | * [api-php-client](https://github.com/shutterstock/api-php-client) 28 | * [shutterstock-php-client](https://github.com/bbaisley/shutterstock-php-client) 29 | 30 | Ruby 31 | 32 | * [ruby-shutterstock-api](https://github.com/shutterstock/ruby-shutterstock-api) 33 | 34 | ## Examples 35 | 36 | * v2: [Javascript][v2-js], [PHP][v2-php] 37 | * v1: [PHP][v1-php] 38 | 39 | [v2-js]: https://github.com/shutterstock/api/blob/master/examples/javascript-jquery/v2.html 40 | [v2-php]: https://github.com/shutterstock/api/blob/master/examples/php-curl/v2.php 41 | [v1-php]: https://github.com/shutterstock/api/blob/master/examples/php-curl/index.php 42 | 43 | ## Contribute 44 | 45 | Please do! Take a look at our [Contributing guide](CONTRIBUTING.md). 46 | 47 | ## License 48 | 49 | [MIT](LICENSE) © Shutterstock Images, LLC 50 | -------------------------------------------------------------------------------- /examples/javascript-jquery/v2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Shutterstock v2 Search Example 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 288 | 289 | 331 | 332 | 333 | 334 |
335 |
336 |

337 | 338 | API Demo 339 |

340 | 341 |
342 |
343 |
344 | 345 |
346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 |
354 |
355 |
356 |
357 | 365 |
366 |
367 |
368 | 374 |
375 | 376 | 382 |
383 |
384 | 385 | 390 |
391 |
392 | 393 | 396 |
397 |
398 | 399 | 407 |
408 |
409 | 410 | 411 | 412 | 413 |
414 | 415 | 416 |
417 |
418 | 419 | 424 | 425 | 434 |
435 |
436 |
437 |
438 |
439 |
440 | 448 |
449 |
450 |
451 | 452 |
453 | 454 |
455 | 456 |
457 | 458 |
459 |
460 |
461 |
462 |
463 |
464 | 467 |
468 |
469 |
470 |
471 |
472 |

Images

473 |
474 |
475 |
476 |
477 |

Videos

478 |
479 |
480 |
481 |
482 |
483 | 484 | 500 | 501 | 502 | -------------------------------------------------------------------------------- /examples/php-curl/.rock.yml: -------------------------------------------------------------------------------- 1 | runtime: php54 2 | 3 | run: exec php -S localhost:8000 4 | -------------------------------------------------------------------------------- /examples/php-curl/README.md: -------------------------------------------------------------------------------- 1 | # PHP (cURL) v1 2 | 3 | 1. Start builtin PHP server (>= 5.4) 4 | 5 | ``` console 6 | $ php -S localhost:8000 7 | ``` 8 | 9 | 1. Open [localhost:8000](http://localhost:8000/) 10 | 11 | 1. Enter API username, API key, and search term 12 | 13 | 1. Click Search 14 | 15 | # PHP (cURL) v2 16 | 17 | 1. Update v2.php with your client_id and client_secret 18 | 19 | 1. Start builtin PHP server (>= 5.4) 20 | 21 | ``` console 22 | $ php -S localhost:8000 23 | ``` 24 | 25 | 1. Open [localhost:8000/v2.php](http://localhost:8000/v2.php) 26 | 27 | 1. Click 'Get Access Token' 28 | 29 | 1. Enter a search term 30 | 31 | 1. Click Search -------------------------------------------------------------------------------- /examples/php-curl/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Shutterstock API PHP Sample Code 5 | 6 | 7 | 8 |

Search

9 | 10 |
11 | 12 | 13 | 14 | 15 |
16 | 17 | username = $username; 26 | $this->key = $key; 27 | } 28 | 29 | protected function getCurl($url) { 30 | if (is_null($this->ch)) { 31 | $ch = curl_init(); 32 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 33 | curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->key); 34 | curl_setopt($ch, CURLOPT_HEADER, 0); 35 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 36 | $this->ch = $ch; 37 | } 38 | 39 | curl_setopt($this->ch, CURLOPT_URL, $url); 40 | 41 | return $this->ch; 42 | } 43 | 44 | public function search($search_terms, $type='images') { 45 | $search_terms_for_url = preg_replace('/ /', '+', $search_terms); 46 | $url = 'http://api.shutterstock.com/' . $type . '/search.json?searchterm=' . $search_terms_for_url; 47 | $username = $this->username; 48 | $key = $this->key; 49 | $ch = $this->getCurl($url); 50 | $json = curl_exec($ch); 51 | return json_decode($json); 52 | } 53 | } 54 | 55 | $api_username = $_GET['api_username']; // Insert your API username here instead of GETting it from browser 56 | $api_key = $_GET['api_key']; // Insert your API key here instead of GETting it from browser 57 | $search_terms = $_GET['search_terms']; // Add your own security checks to cleanse this input 58 | 59 | $api = new ShutterstockAPI($api_username, $api_key); 60 | $images = $api->search($search_terms); 61 | $videos = $api->search($search_terms, 'videos'); 62 | 63 | if ($images) { 64 | for ($i = 0; $i < 3; $i++) { 65 | $description = $images->results[$i]->description; 66 | $thumb = $images->results[$i]->thumb_large->url; 67 | $thumb_width = $images->results[$i]->thumb_large_width; 68 | $thumb_height = $images->results[$i]->thumb_large_height; 69 | 70 | echo '
'; 71 | echo '' . htmlspecialchars($description) . '' . "\n\n"; 72 | echo '
'; 73 | echo '

\n\n"; 76 | } 77 | } 78 | 79 | if ($videos) { 80 | for ($i = 0; $i < 3; $i++) { 81 | $description = $videos->results[$i]->description; 82 | $thumb_mp4 = $videos->results[$i]->sizes->thumb_video->mp4_url; 83 | $thumb_webm = $videos->results[$i]->sizes->thumb_video->webm_url; 84 | $preview_image = $videos->results[$i]->sizes->preview_image->url; 85 | 86 | echo '' . $description . '' . "\n\n"; 87 | echo '\n\n"; 91 | echo '

\n\n"; 94 | } 95 | } 96 | 97 | ?> 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /examples/php-curl/v2.php: -------------------------------------------------------------------------------- 1 | $_GET['code'], 18 | client_id => $client_id, 19 | client_secret => $client_secret, 20 | redirect_uri => $redirect_uri, 21 | grant_type => 'authorization_code' 22 | ); 23 | 24 | $ch = curl_init($url); 25 | curl_setopt($ch, CURLOPT_POST, 1); 26 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 27 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 28 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 29 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 30 | 31 | $response = curl_exec($ch); 32 | curl_close($ch); 33 | 34 | $json = json_decode($response); 35 | 36 | if (json_last_error()) { 37 | echo 'Error: ' . $response . ''; 38 | } else { 39 | $_SESSION['access_token'] = $json->access_token; 40 | } 41 | } 42 | 43 | class ShutterstockAPI { 44 | protected $accessToken; 45 | 46 | public function __construct($accessToken) { 47 | $this->accessToken = $accessToken; 48 | } 49 | 50 | public function search($search_terms, $type = 'images') { 51 | $search_terms_for_url = preg_replace('/\s/', '+', $search_terms); 52 | $url = 'https://api.shutterstock.com/v2/' . $type . '/search?view=full&per_page=5&query=' . $search_terms_for_url; 53 | 54 | $ch = curl_init($url); 55 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->accessToken)); 56 | curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 57 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 58 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 59 | 60 | $response = curl_exec($ch); 61 | curl_close($ch); 62 | 63 | return json_decode($response); 64 | } 65 | } 66 | 67 | ?> 68 | 69 | 70 | 71 | 72 | Shutterstock API v2 PHP Sample Code 73 | 74 | 75 | 76 |

Step 1: Authenticate

77 | 78 |
79 |
80 | Client ID: 81 | 82 |
83 |
84 | Client Secret: 85 | 86 |
87 |
88 | Redirect URI: 89 | 90 |
91 |
92 | Access Token: 93 | 94 |
95 | 96 | 97 |
98 | 99 |

Step 2: Search

100 | 101 |
102 | 103 | 104 | > 105 |
106 | 107 |
108 | 109 | search($search_terms); 116 | $videos = $api->search($search_terms, 'videos'); 117 | 118 | echo '

Images

'; 119 | 120 | if ($images) { 121 | for ($i = 0; $i < 3; $i++) { 122 | $description = $images->data[$i]->description; 123 | $thumb = $images->data[$i]->assets->large_thumb->url; 124 | $thumb_width = $images->data[$i]->assets->large_thumb->width; 125 | $thumb_height = $images->data[$i]->assets->large_thumb->height; 126 | 127 | echo '
'; 128 | echo '' . htmlspecialchars($description) . '' . "\n\n"; 129 | echo '
'; 130 | 131 | echo '

\n\n"; 134 | } 135 | } 136 | 137 | echo '

Videos

'; 138 | 139 | if ($videos) { 140 | for ($i = 0; $i < 3; $i++) { 141 | $description = $videos->data[$i]->description; 142 | $thumb_mp4 = $videos->data[$i]->assets->preview_mp4->url; 143 | $thumb_webm = $videos->data[$i]->assets->preview_webm->url; 144 | $preview_image = $videos->data[$i]->assets->preview_jpg->url; 145 | 146 | echo '' . $description . '' . "\n\n"; 147 | 148 | echo '\n\n"; 152 | 153 | echo '

\n\n"; 156 | } 157 | } 158 | } 159 | 160 | ?> 161 | 162 | 163 | 164 | --------------------------------------------------------------------------------