PHP code example of dolphin.wang / unsplash-random-download
1. Go to this page and download the library: Download dolphin.wang/unsplash-random-download library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dolphin.wang / unsplash-random-download example snippets
use Dolphin\Wang\Unsplash\Random;
// 设置 Unsplash Access Key,如果只需要下载单张图片设置一个 KEY 就可以了,如果需要开启自动下载任务,可以设置多个 KEY,程序会自动切换 KEY 来绕过 Unsplash 的接口请求限制。根据 Unsplash 的接口请求限制规则,建议添加 10 个或以上的 KEY。如果是生产版的应用则不需要设置多个。
$access_key_arr = [
'',
''
];
$dir = 'pic';
$random = new Random($access_key_arr, $dir);
// 下载单张图片
var_dump($random->rand());
// 启动自动下载任务:注意 Unsplash API 的请求限制规则,测试版每小时 50 次,生产版每小时 5000 次,超过限制接口返回 403 错误
$random->run();