导入
用户
了解 Blogger API 中的用户类。
| 参数 | 类型 | 描述 |
|---|---|---|
| kind | string | 对象的类型。值:blogger#user,此值固定不变。 |
| id | string | 用户的 ID。 |
| created | datetime | 用户资料的创建日期。格式:yyyy-mm-dd |
| url | string | 用户资料的公开链接。 |
| selfLink | string | 用户资料的 Blogger API 地址。 |
| blogs | object | 包含用户博客信息的对象。 |
| blogs.selfLink | string | 用户博客集合的 Blogger API 地址。 |
| displayName | string | 用户的名称。 |
| about | string | 用户的个人简介。 |
| locale | object | 包含用户区域设置信息的对象。 |
| locale.language | string | 用户的语言设置。 |
| locale.country | string | 用户的国家设置。 |
| locale.variant | string | 用户的语言变体设置。 |
...
用户资料 URL
1https://blogger.googleapis.com/v3/users/userId
| 参数 | 类型 | 必填项 | 描述 |
|---|---|---|---|
| USER_ID | string | 必须 | 要获取的用户 ID。允许的值:self 或当前用户 ID |
1// 导入库 2import fetch from "node-fetch"; 3 4// 定义访问令牌 5const ACCESS_TOKEN = '{{ACCESS_TOKEN}}'; 6 7// 定义路径参数 8const USER_ID = '{{USER_ID}}'; 9 10// 定义端点 URL 11const endpointUrl = new URL(`https://blogger.googleapis.com/v3/users/${USER_ID}`); 12 13// 定义请求头参数 14const headerParameters = { 15 authorization: `Bearer ${ACCESS_TOKEN}`, 16 contentType: 'application/json', 17}; 18 19// 设置 API 请求选项 20const options = { 21 method: 'GET', 22 headers: headerParameters, 23}; 24 25// 定义发起 API 请求的函数 26async function getUserInfo() { 27 try { 28 const response = await fetch(endpointUrl, options); 29 30 // 输出响应结果 31 printResponse(response); 32 } catch (error) { 33 // 输出错误信息 34 printError(error); 35 } 36} 37 38// 调用函数发起 API 请求 39getUserInfo();