导入
获取域名和Logo
学习并实践如何使用 Clearbit API 获取公司的域名和图标。
...
The name to domain endpoint
代码示例
1https://company.clearbit.com/v1/domains/find?name={公司名称}
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 要查询域名的公司名称。 |
1import fetch from 'node-fetch'; 2 3const API_KEY = 'Bearer {{API_KEY}}'; 4 5const endpointUrl = new URL('https://company.clearbit.com/v1/domains/find'); 6 7const headerParameters = { 8 authorization: API_KEY, 9 contentType: 'application/json', 10}; 11 12const queryParameters = new URLSearchParams({ 13 name: '{{NAME}}' 14}); 15 16const options = { 17 method: 'GET', 18 headers: headerParameters, 19}; 20 21async function fetchData() { 22 try { 23 endpointUrl.search = queryParameters; 24 const response = await fetch(endpointUrl, options); 25 26 // 自定义函数:打印 API 响应 27 printResponse(response); 28 } catch (error) { 29 30 // 自定义函数:打印错误信息 31 printError(error); 32 } 33} 34 35// 调用函数发起 API 请求 36fetchData();
| 字段名 | 类型 | 说明 |
|---|---|---|
| domain | string | 公司的网站域名。 |
| logo | string | 公司 logo 的 URL 地址。 |
| name | string | 公司名称。 |
...
The logo endpoint
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| domain | string | 是 | 公司的网站域名。 |
| size | integer | 否 | 请求图像的尺寸,指图像最长边的像素长度,默认值为 128。 |
| format | string | 否 | 请求图像的格式,可选 "png" 或 "jpg",默认值为 "png"。 |
| greyscale | boolean | 否 | 若为 true,则将图像去色处理,默认值为 false。 |
1const endpointUrl = new URL('https://logo.clearbit.com/{{DOMAIN}}'); 2 3async function fetchData() { 4 try { 5 console.log("<img src="+endpointUrl+" style='display: block; margin-left:auto ;margin-right:auto;'>") 6 } catch (error) { 7 // 自定义函数:打印错误信息 8 printError(error); 9 } 10} 11 12// 调用函数发起 API 请求 13fetchData();
| 字段名 | 类型 | 说明 |
|---|---|---|
| logo | png 或 jpg | 公司 logo 的图像。 |