diff --git a/src/app/()/page.tsx b/src/app/()/page.tsx index 9d58b8d..5aabf76 100644 --- a/src/app/()/page.tsx +++ b/src/app/()/page.tsx @@ -95,7 +95,9 @@ export default function IndexPage() { {/* API Example */}
重要提示:{" "} @@ -104,30 +106,69 @@ export default function IndexPage() {
- {`// 1. 重定向到授权页面(必须通过浏览器重定向,不能使用 AJAX/Fetch)
+ {`// 1. 重定向到授权页面
window.location.href = 'https://connect.q58.club/oauth/authorize?' + new URLSearchParams({
- response_type: 'code',
- client_id: 'your_client_id',
- redirect_uri: 'https://your-app.com/callback'
+ response_type: 'code', // 必填,固定值 'code'
+ client_id: 'your_client_id',// 必填,在控制台获取的客户端ID
+ redirect_uri: 'https://your-app.com/callback' // 必填,授权后的回调地址
});
-// 2. 在回调页面获取访问令牌
+// 2. 获取访问令牌
const response = await fetch('https://connect.q58.club/api/oauth/access_token', {
method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ },
body: new URLSearchParams({
- code: '授权码',
- redirect_uri: 'https://your-app.com/callback'
+ code: '授权码', // 上一步回调地址获取的 code 参数
+ redirect_uri: 'https://your-app.com/callback' // 必须与授权请求中的一致
})
});
-const { access_token } = await response.json();
+
+// 返回数据示例:
+{
+ "access_token": "at_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // 访问令牌
+ "token_type": "bearer", // 令牌类型
+ "expires_in": 604800 // 令牌有效期(秒)
+}
// 3. 获取用户信息
const userInfo = await fetch('https://connect.q58.club/api/oauth/user', {
headers: {
- 'Authorization': \`Bearer \${access_token}\`
+ 'Authorization': \`Bearer \${access_token}\` // 使用上一步获取的访问令牌
}
-}).then(res => res.json());`}
+}).then(res => res.json());
+
+// 返回数据示例:
+{
+ "id": "user_xxxxxx", // 用户唯一标识
+ "email": "user@example.com", // 用户邮箱
+ "username": "username", // 用户名
+ "name": "用户昵称", // 用户昵称
+ "avatarUrl": "https://...", // 头像URL
+ "admin": false, // 是否是管理员
+ "moderator": false, // 是否是版主
+ "groups": ["group1", "group2"] // 用户所属的论坛用户组
+}`}
+ + 权限说明: +
++ 安全建议: +
+