第 3 步:创建访问令牌和刷新令牌
您通过 OAuth2.0 发出的 API 请求通常用 access_token 进行身份验证,它作为持有者令牌进行传递。
为了使用此 access_token,您需要构造常规 HTTP 请求,将其与持有者的值一同包含在授权标头中。
请注意,"access_token" 将在 1 小时内到期。
请求参数
现在使用以下参数对您自己进行授权:
参数 | 数据类型 | 描述 |
必需参数 | ||
grant_type | 字符串 | 输入 grant_type = authorization_code。 |
client_id | 字符串 | 在 Zoho 开发者控制台中找到的 client_id。 |
client_secret | 字符串 | 在 Zoho 开发者控制台中找到的 client_secret。 |
redirect_uri | 字符串 | 指定在应用程序注册期间所提供的回调 URL。 |
response_type | 字符串 | 输入 response_type 为 code。 |
可选参数 | ||
access_type | 字符串 | 指定 access_type 为 online 或 offline。 如果您要生成 refresh_token,请将 access_type 值设为 offline。 |
To generate access_token, do the following:
1. Make a POST request with the following URL:
https://accounts.zoho.com/oauth/v2/token?
code={grant_token}&=https://www.zoho.com/&client_id={client_id}
&client_secret={client_secret}
&grant_type=authorization_code
2. On successful request, you will receive the following:
{
"access_token" : "{access_token}",
"refresh_token" : "{refresh_token}",
"expires_in_sec": 3600,
"api_domain" : "https://writer.zoho.com" ,
"token_type" : "Bearer",
"expires_in" : 3600000
}
This completes the authorization process. Once your app receives the access_token, send it via the HTTP authorization header to Writer's API with value as "Zoho-oauthtoken {access_token}" for each endpoint.