如何允许 Facebook 访问受保护的内容

发布于 2024-12-05 14:00:22 字数 504 浏览 2 评论 0原文

我在受密码保护的页面上使用 Facebook 评论。我最近发现,当创建新帖子时,我收到错误“facebook comments {page} 无法访问”,并且当我使用 Facebook 的调试工具进行调试时,找不到 ID。 FB 命名空间、元标记和 js 均已正确插入,并且在所有非受保护页面上都能正常工作。

当我禁用密码保护并刷新页面时,一切正常,并且在正确加载后,当我重新启用密码保护时,一切似乎都很好。

所以我猜 Facebook 需要能够第一次访问该页面才能将其设置在数据库中?

有什么办法可以让 Facebook 最初访问该页面。例如,在我的验证函数中,我可以添加:

if( can_user_view_content() || is_request_from_facebook() ){
    //echo content and comments

Facebook 是否发送我可以使用的用户代理字符串,或者是否有比测试用户代理更好的方法?

谢谢

I am using Facebook comments on password protected pages. I have recently found that when a new post is created I get the error 'facebook comments {page} is unreachable' and when I debug using Facebook's debug tool no ID is found. FB Namespace, meta tag and js are all inserted correctly and work fine on all non protected pages.

When I disable the password protection and refresh the page everything works fine and after being loaded correctly that once it seems to be fine when I re enable the password protection also.

So I guess Facebook needs to be able to access the page the first time to set it up in it's database?

Is there a way I can allow Facebook to access the page initially. For example in my verification function I could add:

if( can_user_view_content() || is_request_from_facebook() ){
    //echo content and comments

Does Facebook send a useragent string I could use or is there a better way than testing for user agent?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫﹏色ふ单纯 2024-12-12 14:00:22

Facebook 的机器人通常使用用户代理标头 FacebookExternalHit/1.1FacebookExternalHit/1.0 进行操作(但版本号可能会在某个时刻增加)

如果您通常将内容设置为登录用户但需要爬虫到达您的页面,请注意,只要返回开放图元标记,您就不需要将完整内容返回给爬虫
(即在登录页面的常规内容上也放置您使用的相同标签)

Facebook's bot usually operates with the user agent header FacebookExternalHit/1.1 or FacebookExternalHit/1.0 (but the version number could increment at some point)

If you normally gate your content to logged in users but need the crawler to reach your page, note that you don't need to return the full content to the crawler provided that the open graph meta tags are returned to it
(i.e put the same tags you'd use on the regular content for the login page also)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文