查询条已从打开的图形 URL 中删除

发布于 2024-12-25 20:48:31 字数 327 浏览 1 评论 0原文

关于这个问题: Facebook 的动态生成Open Graph 元标记

我已遵循这些说明,但 api 似乎删除了我的查询字符串,以便传递到聚合中的 url 不包含我的动态信息。如果我将带有查询字符串的 url 输入到调试器中,它不会将其删除并且工作正常。我可以确认我的 og:url 元标记也包含相同的查询字符串,而不仅仅是基本 URL。我做错了什么?

In relation to this question: Dynamic generation of Facebook Open Graph meta tags

I have followed these instructions but the api seems to remove my query string so that the url passed into the aggregation contains none of my dynamic information. If I enter the url with the query string into the debugger it doesn't remove it and works fine. I can confirm my og:url meta tag does also contain the same query string not just the base url. What am I doing wrong?

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

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

发布评论

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

评论(1

做个ˇ局外人 2025-01-01 20:48:31

我遇到了类似的问题并像这样解决了它:

所以假设您正在执行帖子请求,就像 tutorial,你的 Javascript 可能看起来像这样:

  function postNewAction()
  {
      passString = '&object=http://yoursite.com/appnamespace/object.php';

      FB.api('/me/APP_NAMESPACE:ACTION' + passString,'post',
         function(response) {
              if (!response || response.error) {
                  alert(response.error.message);
              } 
              else {
                  alert('Post was successful! Action ID: ' + response.id);
              } 
          }
      );    
  }

既然你说你想动态生成元标记,你可能会像这样向 url (passString) 添加一个参数:

  passString = '&object=http://yoursite.com/appnamespace/object.php?user=' + someuser;

这是错误的。

您需要做的就是使 url 成为“漂亮的 url”并使用 htaccess 对其进行解密。所以:

  passString = '&object=http://yoursite.com/appnamespace/object/someuser';

然后你的 htaccess 文件会告诉你的网站,该 url 实际上等于

  http://yoursite.com/appnamespace/object/object.php?user=someuser

然后你可以使用 GET 将用户参数与 php 一起存储,然后将其插入你的元标记中。

如果您想知道,在 og:url 元标记的内容中将是:

  $url = 'http://yoursite.com/appnamespace/object/object.php?user=' . $_GET[$user];

这有帮助吗?

I was having a similar issue and solved it like this:

So assuming you're doing your post request like it shows in the tutorial, youre Javascript probably looks something like this:

  function postNewAction()
  {
      passString = '&object=http://yoursite.com/appnamespace/object.php';

      FB.api('/me/APP_NAMESPACE:ACTION' + passString,'post',
         function(response) {
              if (!response || response.error) {
                  alert(response.error.message);
              } 
              else {
                  alert('Post was successful! Action ID: ' + response.id);
              } 
          }
      );    
  }

And since you say you want to generate meta tags dynamically, you're probably adding a parameter to the url (passString) there like so:

  passString = '&object=http://yoursite.com/appnamespace/object.php?user=' + someuser;

This is wrong.

What you need to do is to make the url a 'pretty url' and use htaccess to decipher it. So:

  passString = '&object=http://yoursite.com/appnamespace/object/someuser';

Then your htaccess file will tell your site that that url actually equates to

  http://yoursite.com/appnamespace/object/object.php?user=someuser

Then you can use GET to store the user parameter with php and insert it however you like into your meta tags.

In case youre wondering, in the og:url meta tag's content will be:

  $url = 'http://yoursite.com/appnamespace/object/object.php?user=' . $_GET[$user];

Does that help?

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