将 Discourse 论坛链接到 WP Discourse 时遇到问题

Hello,

I’m working on a wordpress site and have the WP Discourse plugin installed. Our objective is obviously to sync our wordpress site with the Discourse forum so that when a post is published to the site it is also published to Discourse.

However until now it didn’t work much. While creating a post, even with the “Create new Topic” Discourse box checked, it does not work and the post isn’t created in the forum.

I went to the WP Discourse plugin settings and to me everything seemed to be fine (everything isn’t obviously fine and I may have done something wrong as it doesn’t work), the Discourse API key is correct as well as the SSO secret key, as I’m also trying to use my wordpress site as an SSO provider.

I noticed in the WP Discourse plugin settings that there were two error messages, when accessing the “SSO Provider” and “Connection” tabs:


which is quite problematic because there IS an admin user with this email address on the forum (myself).
and most importantly, “You are not connected to Discourse. If you are setting up the plugin, this notice should go away after completing the form on this page.”

Soooo my wordpress and Discourse don’t seem to be synced. Can I please get some help in order to solve this ? Feel free to ask if you need more information - I guess you obviously do

The first thing to sort out is the issue on the Connections tab. The plugin won’t work until you establish a connection with Discourse.

What have you set for the Publishing Username on that tab? It should be set to either the Discourse username of the system user (‘system’ by default) or the username of an admin user from your forum.

What version of WordPress are you using?

3 个赞

Hello Simon, thanks for the answer.

So it seems really dumb, but as expected the Publishing Username wasn’t correct (I missed a space on the name). I fixed this and now I have the “You are connected to Discourse!” message.

Also no more error message on the SSO Provider tab. By the way I’m using WordPress 4.9.3.

Anyway, sorry for the inconvenience and thanks again for the answer. I’ll update this thread/create another one if I have any other issue especially with synchronizing the creation of posts between Wordpress and the forum.

3 个赞

Hi,

Although I put all the needed info to Connection tab but it still shows

You are not connected to Discourse. If you are setting up the plugin, this notice should go away after completing the form on this page.

Please help.

Discourse: https://forum.biohack.vn
WP: https://biohack.vn
I use admin as the username since it’s the Discourse admin.

Try using ‘system’ for the username.

1 个赞

Already before I switch to admin.

For the Publishing Username setting, you need to use the username of your Discourse System user. That username defaults to ‘system’ (without the quotes.) For the API Key, use the All Users API Key. You can find that key at /admin/api/keys.

When I try to visit your site at http://biohackplus.com/, the page isn’t loading for me. Are you able to access it at that URL?

Let’s not open more than one topic on the same exact thing please.

2 个赞

I was able to connect to Discourse. However, although I put all the needed info Publishing tab, when I create a post in Wordpress, it doesn’t show in Discourse.

What I’m trying to do: When I create a post in a category in Wordpress, the plugin will create a post in Discourse with link to my Wordpress post in a matched Discourse Category.

This topic has instructions for publishing posts to Discourse: WP Discourse now supports the WordPress Block Editor. Is this working for you?

1 个赞

我的网站也有类似的问题。我安装了 WP Discourse,创建了一个所有用户密钥,发布用户名为 system,但我仍然看到“您未连接到 Discourse…"。我的网站通过 Cloudflare 代理,但据我所知,代理工作正常。非常感谢您的任何帮助。Discourse 版本为 2.6.0.b4。

嘿,@sturdy2,你遇到的问题可能有几个原因。能否请你尝试一下这个配置?

在 Discourse 中:为管理员用户创建一个全局 API 密钥

配置应如下所示:

在 WordPress 中:使用该密钥,并将“发布用户名”设置为你所选的管理员用户

(你的“Discourse URL”字段应填写你的 Discourse 网址,而不是截图中显示的内容)

1 个赞

你好 @angus,感谢回复。不幸的是,按照您所说创建单用户密钥后,我仍然收到“无连接”的提示。我已经尝试了所有能想到的方法,但问题依旧……再次感谢。

好的,让我们看看能否解决这个问题。

确认一下,您创建的是“全局密钥”(允许所有操作)吗?

假设您确实创建了,请检查以下内容:

  1. 您的 Discourse 托管在哪里?您的 WordPress 托管在哪里?

  2. 您是否安装了任何自定义的 Discourse 插件?

  3. 请在 WordPress 上安装此 健康检查插件

    • 该插件是否检测到任何严重问题?

    • 启用故障排除模式,仅启用 wp-discourse 插件(所有其他插件将被禁用)。然后再次尝试连接。

1 个赞

是的,全局密钥,单用户(即我本人,管理员)。WP Discourse 无法连接。

  1. Discourse 由 DO 托管。
  2. 不确定关于自定义插件的情况。
    3a. “健康检查与故障排除”(即站点检查)已安装一段时间。Yoast SEO 报告的一个可疑“严重问题”是“搜索引擎无法找到您的站点”。进一步的故障排除说明指出:“如果 Google 可以运行移动友好性测试,那么 Google 也可以抓取该域名。在这种情况下,Ryte 的警告是错误的。”域名和子域名均通过了测试。
    3b. 之前尝试过,现在再次尝试。除 WP Discourse 外,所有插件均已禁用。WP Discourse 仍无法连接。

更新:我已经折腾了好几天,有几点我不太明白,可能是因为这一切对我来说都太新了。

  1. discourse 子域名的 DNS "A"记录指向 DO 分配的 IP(与我用于 SSH 的 IP 相同),但 dig discourse.example.com 却指向三个 apparently 由 Cloudflare 分配的不同 IP,而 dig https://discourse.example.com 则指向另一个 IP whois BAREFRUIT-ERRORHANDLING,位于英国。这里肯定有问题!

  2. 我假设 WP Discourse 使用 cURL 连接 Discourse,因此我一直在尝试 cURL 和 Discourse API。我有三个 API 密钥(包括上面确认的那个)。直到昨天,这三个密钥都显示“从未使用”。昨天,我注意到去年八月创建的那个原始密钥现在显示“一天前已使用”!另外两个仍显示“从未使用”。我推测这意味着我的一个或多个 cURL 实验确实成功连接了;遗憾的是,我不知道具体是哪一个成功了。我还注意到,产生 HTTP 200 响应的 cURL 命令并不会更新 API 的“最后使用”信息(仍显示“从未使用”)。

上述第 1 点和第 2 点对我来说似乎都很重要,但我暂时还无法确定具体问题所在。

抱歉回复晚了,有时生活琐事会干扰。再次感谢 @angus 的帮助。

好的,能否尝试从您的配置中移除 Cloudflare?我们需要缩小潜在错误来源的范围。

1 个赞

你好 @angus

又一个更新:我安装了 Query Monitor 插件(在 WordPress 中)(参见下方的输出)。

在我本地计算机上使用 cURL 时,同样收到 403 错误。因此我认为这是上游问题,涉及我的网站和 WP Discourse。可能是 Cloudflare 导致的,但我不想现在就移除 Cloudflare。详见下文。

再次为我的迟缓致歉。我收到了托管服务商的通知,我的网站将被迁移到另一台服务器,期间会有一些变更,包括 IP 地址的更改。因此,我需要暂缓对此问题的进一步处理。待一切稳定后,我可以再向您求助吗?

编辑:已解决!问题可能出在 /admin/site_settings/category/security → 允许的爬虫用户代理(allowed crawler user agents)设置上。
看起来,只要在“允许 UA”文本框中输入任何内容,就会导致所有请求被拦截,包括从我本地计算机发出的 cURL 命令行请求。将该文本框重置为空后,WP Discourse 立即显示“您已成功连接到 Discourse!”。

3 个赞

很高兴你解决了问题!:tada:

是的,我认为该设置本意就是相当严格的(因此说明中使用了全大写的警告)。

若要在启用 allowed crawler user agents 的同时允许你的 WordPress 实例通过,可以按如下方式添加:

Wordpress/<wordpress_version>

我刚刚在我的测试环境(WordPress / Discourse)中测试了添加 Wordpress/5.5.3allowed crawler user agents 的功能,效果很好 :+1:

如果你不想每次升级 WordPress 时都手动更新该列表,可以使用一个简单的插件来为这类请求自定义用户代理,例如:

https://github.com/webdeveric/wp-user-agent

2 个赞

感谢您的解释,这让我开始逐渐理解了。起初,我以为“允许的爬虫用户代理”是指允许搜索引擎爬虫的标识。我当时输入了“Googlebot”,却没意识到 WP Discourse 使用的是 WordPress 用户代理,结果被拦截了。这又是一个新手的常见错误。我想这应该是一个普遍的误解,但在有限的文档和更少的示例中,我找不到任何相关说明。

目前,在“允许的爬虫用户代理”中,我设置了:WordPress(无需指定版本)、Googlebot,以及 Discourse(为配合下方的 cURL 使用而添加)。您觉得这样有问题吗?或者我还需要添加其他内容?

在使用 cURL 调用 Discourse API 时,情况也类似。我之前一直收到 403 错误,直到我按如下方式添加了用户代理才解决。

Discourse API 文档中的第一个示例(对我无效):
curl -X GET "http://127.0.0.1:3000/admin/users/list/active.json" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: system"
在添加用户代理选项后,这个示例对我有效:
curl -A Discourse -X GET "http://discourse.example/admin/users/list/active.json" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: system"

依我之见,示例只有在完整且可运行的情况下才应该发布……真是让人抓狂。

@angus,非常感谢您的帮助和支持。

1 个赞

您好,

据我所知,唯一同时支持 WordPress 和 Discourse 的会员插件是 Memberful。他们在这里提供了详细的 Discourse 集成指南:Integrate Discourse with Memberful - Memberful

如果您已在使用其他会员插件,建议直接联系他们进行咨询。我曾在我的 客户网站作品集 中使用过该插件。

2 个赞