重新生成访问令牌
学习如何使用刷新令牌重新生成访问令牌。
// 导入所需库 const fetch = require('node-fetch');
const endpointUrl = new URL('https://api.freshbooks.com/auth/oauth/token');
const requiredIds = Buffer.from('{{SECRET_ID}}:{{SECRET_KEY}}'); const encoded = requiredIds.toString('base64');
headerParameters = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer ' + encoded }
const bodyParameters = new URLSearchParams({ grant_type: 'refresh_token', client_id: '{{SECRET_ID}}', client_secret: '{{SECRET_KEY}}', refresh_token: '{{REFRESH_TOKEN}}', redirect_uri: '{{REDIRECT_URI}}/callback', });
const options = { method: 'POST', headers: headerParameters, body: bodyParameters, };
async function refreshAccessToken() { try { const response = await fetch(endpointUrl, options); printResponse(response); } catch (error) { printError(error); } }
refreshAccessToken();