简易 NeoDB access_token 获取教程

以下内容为获取 NeoDB access_token 的精简步骤,请严格按顺序执行并核对所有参数。


1 注册 OAuth 客户端

curl -X POST https://neodb.social/api/v1/apps \
  -d "client_name=YourAppName" \
  -d "redirect_uris=urn:ietf:wg:oauth:2.0:oob" \
  -d "scopes=read write follow" \
  -d "website=https://your.website/optional"

返回 JSON,其中包含:

  • client_id(例如 tk-...
  • client_secret(例如 ...

注意:务必妥善保存 client_idclient_secret


2 获取一次性授权码(Authorization Code)

构造并在浏览器打开:

https://neodb.social/oauth/authorize?response_type=code&client_id=<client_id>&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read%20write%20follow

  • <client_id> 替换为第 1 步返回的值。
  • redirect_uri=urn:ietf:wg:oauth:2.0:oob 要与第 1 步填写一致。
  • scope 与第 1 步一致,用 %20 分隔。

点击 “Authorize”,复制浏览器显示的授权码 code

注意:授权码有效期短且仅能使用一次,请复制后立即进行下一步。


3 使用授权码换取 access_token

curl -X POST https://neodb.social/oauth/token \
  -d "client_id=<client_id>" \
  -d "client_secret=<client_secret>" \
  -d "code=<authorization_code>" \
  -d "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
  -d "grant_type=authorization_code"

<client_id><client_secret><authorization_code> 替换为实际值。

响应示例:

{
  "access_token": "XXXXXXXXXXXXXXXXXXXX",
  "token_type": "Bearer",
  "scope": "read write follow"
}

常见错误:

  • invalid_grant / access_denied:授权码无效或已使用;
  • invalid_clientclient_idclient_secret 填写有误。

4 验证并使用 access_token

Swagger UI(Developer Console)

  1. 打开 https://neodb.social/developer/,点击右上角 Authorize
  2. 在弹窗 “Value” 处粘贴:
    Bearer <access_token>
  3. 点击 “Authorize” 后,即可调用受保护接口。

命令行验证

curl -H "Authorization: Bearer <access_token>" \
     -X GET https://neodb.social/api/me

返回用户信息 JSON 表示令牌有效。


5 注意事项

  • 授权码有效期短,且只能使用一次,必须复制后立即兑换。
  • redirect_uriclient_idclient_secretcode 均需一字不差。
  • access_token 默认长期有效,除非在 NeoDB 用户设置中手动撤销(Revoke)。
  • 如需撤销,请登录 NeoDB → “Settings” → “Authorized Applications” → 点击 “Revoke”。

以上便是获取 NeoDB access_token 的精简指南,遵循此流程可快速拿到可长期使用的访问令牌。

 

支持

Leave a Comment