Access Token là một chuỗi ký tự cho phép dịch vụ của bạn có thể sử dụng AICall APIs.
Last updated 1 year ago
Lấy thông tin API_KEY, API_SECRET từ ứng dụng đã tạo
Tạo ACCESS_TOKEN
Bạn cần tạo Access Token bằng thực thi các câu lệnh, dưới đây là các câu lệnh mẫu theo các ngôn ngữ:
const jwt = require('jsonwebtoken'); const API_KEY = '<API_KEY>'; const API_SECRET = '<API_SECRET>'; const ACCESS_TOKEN = jwt.sign({ apiKey: API_KEY }, API_SECRET);
import jwt API_KEY = '<API_KEY>' API_SECRET = '<API_SECRET>' ACCESS_TOKEN = jwt.encode({ apiKey: API_KEY }, API_SECRET)
package org.example; import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; import java.util.Date; public class Main { public static void main(String[] args) { String API_KEY = "<API_KEY>"; String API_SECRET = "<API_SECRET>"; Algorithm algorithm = Algorithm.HMAC256(API_SECRET); // Include the "iat" claim with the current timestamp long currentTimeMillis = System.currentTimeMillis(); String ACCESS_TOKEN = JWT.create() .withClaim("apiKey", API_KEY) .withIssuedAt(new Date(currentTimeMillis)) // Include "iat" claim .sign(algorithm); } }
<?php use \Firebase\JWT\JWT; $API_KEY = '<API_KEY>'; $API_SECRET = '<API_SECRET>'; $ACCESS_TOKEN = JWT::encode([ "apiKey" => $API_KEY ], $API_SECRET, 'HS256');
Sau khi thực thi code mẫu trên bạn nhận về ACCESS_TOKEN