# 按用户 API 密钥不起作用

**URL:** https://meta.discourse.org/t/per-user-api-keys-not-working/201415
**Category:** Support
**Created:** [2021 年8 月 23 日 11:16 UTC](https://meta.discourse.org/t/per-user-api-keys-not-working/201415 "2021-08-23T11:16:20Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [2021 年9 月 2 日 15:47 UTC](https://meta.discourse.org/t/per-user-api-keys-not-working/201415/3 "2021-09-02T15:47:32Z")

</div>

我已经让它运行起来了。@RGJ 很有帮助地指出了以下几点：

当 Discourse 执行重定向并将 API 密钥作为重定向 URL 中的有效负载进行解码时，该密钥会经过 URL 编码。因此，要获取实际的 API 密钥，你需要对有效负载进行 URL 解码。解码后的结果就是正常工作的 API 密钥（其长度与 Discourse 在屏幕上显示的密钥长度一致）。

我在此提供了我遵循的使其正常工作的步骤：

> [@User API keys specification](https://meta.discourse.org/t/user-api-keys-specification/48536/45):
>
> I have gotten this to work, after some trial and error. Here are the basic steps that I follow when: I have a separate app that I have coded, and I want users to be able to use that app to make API calls to a discourse site. To do that, I need to generate a per-user API token to make calls on behalf of each specific user (at least in a nodejs/javascript environment). Note that for the javascript side of things, I found the code that @KengoTODA provided here: [discourse-api-key-generator/src/i…](https://github.com/KengoTODA/discourse-api-key-generator/blob/main/src/index.ts)

---

_[View the full topic](https://meta.discourse.org/t/per-user-api-keys-not-working/201415)._
