Alv*_*par 3 sendgrid sendgrid-api-v3
我可以从Web应用程序获取API密钥.但是,根据SendGrid文档,我只能访问整个密钥的一小部分.
如果您看到以下API密钥示例:
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
Run Code Online (Sandbox Code Playgroud)
子字符串"ngeVfQFYQlKU0ufo8x5d1A"是API密钥.
这些内容的其余部分是什么?它们是如何生成整个/完整字符串的?
*解决*
API KEY仅生成并显示给您一次.所以一定要复制并保存在某个地方.之后,仅显示子集键.
子字符串
"ngeVfQFYQlKU0ufo8x5d1A"是 API 密钥。
您所指的子字符串不是API 密钥,而是 API 密钥 ID。
这些东西的其余部分是什么?它们是如何生成整个/完整字符串的?
完整的字符串是整个 API 密钥,它分为 3 个部分并用点分隔。所以API KEY = SG.ID.VALUE:
SG.aaaa.bbbb,api_key_id则将是aaaa.如何获取完整的 SendGrid API 密钥?
这样做的方法只有两种;通过SendGrid UI或 API。两者都在创建时访问,您只能读取一次键值。
这是通过 Node.js使用官方 SendGrid Web API v3 客户端的示例:
import sgClient from '@sendgrid/client';
/** Your initial API key from the SendGrid UI */
sgClient.setApiKey(process.env.SENDGRID_API_KEY);
let req = {
method: 'POST',
url: '/v3/api_keys',
body: { name: 'NEW_SG_KEY' }
};
sgClient.request(req)
.then( ([res, body]) => {
console.log(`key: ${body.api_key}`);
console.log(`ID: ${body.api_key_id}`);
})
.catch( err => {
console.log(`Unable to create new API key: ${err.code} ${err.message}`);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5020 次 |
| 最近记录: |