接入教程
1. 注册Clearbit账号获取API密钥
2. 通过公司名称或域名构造API请求URL
3. 调用接口获取Logo图像数据
4. 可选择尺寸和格式参数进行定制
5. 将返回的图像URL嵌入到项目中使用
通过域名获取公司Logo
python
import requests
url = 'https://logo.clearbit.com'
domain = 'example.com'
response = requests.get(f'{url}/{domain}')
if response.status_code == 200:
with open('logo.png', 'wb') as f:
f.write(response.content)
print('Logo downloaded successfully')
else:
print('Logo not found')
使用API密钥验证获取Logo
php
<?php
$api_key = 'YOUR_API_KEY';
$domain = 'example.com';
$url = 'https://logo.clearbit.com/' . urlencode($domain);
$options = [
'http' => [
'header' => "Authorization: Bearer $api_key\r\n"
]
];
$context = stream_context_create($options);
$image_data = file_get_contents($url, false, $context);
if ($image_data !== false) {
file_put_contents('company_logo.png', $image_data);
echo 'Logo saved successfully';
} else {
echo 'Failed to retrieve logo';
}
?>
在网页中动态加载Logo
javascript
const domain = 'example.com';
const apiKey = 'YOUR_API_KEY';
const logoUrl = `https://logo.clearbit.com/${domain}`;
async function loadCompanyLogo() {
try {
const response = await fetch(logoUrl, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
if (response.ok) {
const logoImg = document.createElement('img');
logoImg.src = logoUrl;
logoImg.alt = `${domain} logo`;
document.getElementById('logo-container').appendChild(logoImg);
} else {
console.log('Logo not available');
}
} catch (error) {
console.error('Error loading logo:', error);
}
}
// Call function when page loads
window.addEventListener('DOMContentLoaded', loadCompanyLogo);
常见问题
该API支持哪些格式的Logo图像?
Clearbit Logo API主要返回PNG格式的图像,支持透明背景,确保在各种背景下都能良好显示。大多数Logo提供多种尺寸选项,可通过URL参数指定所需尺寸。
是否需要API密钥才能使用?
基础查询功能通常无需API密钥即可使用,但高级功能、更高请求频率或商业用途需要注册获取API密钥。建议查阅官方文档了解当前的具体认证要求。
如何提高Logo搜索的准确率?
为提高搜索准确率,建议使用完整的公司域名(如google.com而非google),避免使用缩写。如搜索结果不准确,可尝试使用公司法定名称或品牌名称进行搜索。API也支持通过公司名称直接检索。
Aitishiku.com