接入教程
1. 访问Pixel Encounter官网
2. 浏览或搜索图标库选择图标
3. 自定义图标颜色、大小等属性
4. 生成SVG代码或下载图标文件
5. 将图标集成到您的项目中
获取随机图标
python
import requests
base_url = 'https://api.pixelencounter.com/v1'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
response = requests.get(f'{base_url}/icons/random', headers=headers)
if response.status_code == 200:
icon_data = response.json()
print(f'Icon ID: {icon_data["id"]}')
print(f'SVG Content Length: {len(icon_data["svg"])}')
else:
print(f'Error: {response.status_code}')
print(response.text)
搜索特定图标
php
<?php
$base_url = 'https://api.pixelencounter.com/v1';
$api_key = 'YOUR_API_KEY';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . '/icons/search?query=animal&limit=10');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
$data = json_decode($response, true);
echo 'Found ' . count($data['results']) . ' icons';
foreach ($data['results'] as $icon) {
echo '\nIcon: ' . $icon['name'] . ' (ID: ' . $icon['id'] . ')';
}
} else {
echo 'Error: ' . $http_code . '\n' . $response;
}
?>
生成自定义图标
javascript
const baseUrl = 'https://api.pixelencounter.com/v1';
const apiKey = 'YOUR_API_KEY';
async function generateIcon() {
try {
const response = await fetch(`${baseUrl}/icons/generate`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
theme: 'technology',
color: '#3B82F6',
size: 64
})
});
if (response.ok) {
const iconData = await response.json();
console.log('Generated Icon ID:', iconData.id);
console.log('SVG Size:', iconData.size, 'bytes');
} else {
console.error('Error:', response.status, await response.text());
}
} catch (error) {
console.error('Request failed:', error);
}
}
generateIcon();
常见问题
如何获取API密钥?
请访问Pixel Encounter官方网站,注册账户后在开发者控制台创建API密钥。免费套餐提供一定数量的API调用额度。
API支持哪些图标格式?
主要提供SVG格式的矢量图标,也支持转换为PNG、JPG等栅格格式。所有图标都支持自定义颜色、尺寸等参数。
API调用频率有限制吗?
是的,根据不同的套餐等级有相应的调用频率限制。免费套餐每分钟最多30次请求,如需更高限制请升级套餐。
Aitishiku.com