const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
const client = new SecretManagerServiceClient();
const [version] = await client.accessSecretVersion({
name: 'projects/YOUR-PROJECT-ID-HERE/secrets/api-token/versions/latest'
});
const apiToken = version.payload.data.toString();
其中,YOUR-PROJECT-ID-HERE需要替换为您的项目ID。如果您已经登录到Cloud Console,您可以在菜单栏中看到您的项目ID。 5. 您现在可以在App脚本中使用检索到的API令牌。例如:
const response = UrlFetchApp.fetch('https://api.example.com', {
headers: {'Authorization': 'Bearer ' + apiToken}
});