使用 Discourse API 更改头像失败

我有一个具有“全局”访问权限的 API 密钥,适用于“所有用户”。

我这样做:

$updateAvatarUrl = sprintf("%s/u/%s/preferences/avatar/pick.json", $this->apiHost, $username);
$headers = array(
    "Api-Key: ".$this->apiKey,
    "Api-Username: ".$this->apiUsername
);
$data = array(
    'upload_id' => $uploadId,
    'type' => 'uploaded'
);
$response = Q_Utils::put($updateAvatarUrl, $data, null, null, $headers);

但我收到的结果是:

{"failed":"FAILED"}

我也尝试将其发送为 application/json。这是完整的 CURL 信息:

$url = 'https://community.intercoin.app/u/fdhsjkgfs_dghjkl';

Headers:
0:
"Host: community.intercoin.app"
1:
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (K HTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
2:
"Content-Type: application/x-www-form-urlencoded"
3:
"Content-Length: 28"
4:
"Api-Key: 3cf975095fd50e22e3631dc916c6d2c7694419ed421338dd7bba432ba1e71417"
5:
"Api-Username: system"

body:

upload_id=2159&type=uploaded

您可以看到 Profile - fdhsjkgfs_dghjkl - Intercoin 存在。
上传 ID 确实也存在,这是我上传后得到的结果:

{
  "id": 2159,
  "url": "https://community.intercoin.app/uploads/intercoin/original/2X/c/ce6121fe1571faa6c41ad28afdf6c30939ffbc56.png",
  "original_filename": "400.png",
  "filesize": 20636,
  "width": 360,
  "height": 360,
  "thumbnail_width": 360,
  "thumbnail_height": 360,
  "extension": "png",
  "short_url": "upload://trIsPeqspDPRwbMsOnjtDCBBMwK.png",
  "short_path": "/uploads/short-url/trIsPeqspDPRwbMsOnjtDCBBMwK.png",
  "retain_hours": null,
  "human_filesize": "20.2 KB"
}

那么问题出在哪里?我遵循了文档的说明……

1 个赞

另外,不知何故,在我使用 CURL 设置描述和网站中的链接后,它们无法点击:

但在其他摘要框中,它们是可以点击的。使用的 URL 相同。

我在这里哪里做错了?

        Q_Utils::put($this->apiHost."/u/$username.json", array(
            'title' => 'Forum Engagement Bot',
            'bio_raw' => 'Powered by https://engageusers.ai',
            'website' => 'https://engageusers.ai'
        ), null, null, $headers);
1 个赞

最后……在论坛控制面板中,是否有任何方法可以让摘要框完全显示给公众(包含个人简介、网站等),而不是只显示有限的信息?

也许是因为这些用户达到了信任等级 1。为了防止垃圾邮件,新用户的链接不起作用。

是否可以通过 API 设置用户的信任级别?

我刚在这里搜索过,找到了

所以看起来是可能的。

2 个赞

顺便说一句,原始问题的答案是“SSO 覆盖头像”已开启。关闭它解决了问题。

我还通过 API 成功升级了信任级别,这导致了完整摘要框的出现。谢谢,伙计们!

5 个赞