简体   繁体   English

Django App的Facebook分享按钮

[英]Facebook Share Button from Django App

My Facebook share button is not picking up the meta tags on my Django app. 我的Facebook分享按钮未在我的Django应用中获取元标记。 I'm now trying a more custom function but get an error "could not resolve object at URL http://localhost:8000/ ." 我现在正在尝试使用更多自定义函数,但收到错误消息“无法解析URL http:// localhost:8000 /的对象”

I've tried many different approaches and I can't get the meta tags to work or else I get this 'resolve object' error. 我尝试了许多不同的方法,但我无法使meta标签正常工作,否则会出现此“解析对象”错误。 I have ' http://localhost:8000/ ' specified as my Site URL in the Facebook App settings. 我在Facebook App设置中将“ http:// localhost:8000 / ”指定为我的站点URL。 I want users to be able to share to facebook the {{ poll.question }} content from my html page...where am I going wrong? 我希望用户能够将我的HTML页面上的{{ poll.question }}内容共享给Facebook ...我在哪里出错?

<meta property="og:url"                content="http://localhost:8000/" />
<meta property="og:type"               content="article" />
<meta property="og:title"              content="Check out this forecast on CASSIE: {{ poll.question }}"/>
<meta property="og:description"        content="Join Cassie to forecast this and more! See how accurate you are at \
                                                predicting the future!" />
<meta property="og:image"              content="{{MEDIA_URL }}/social/logo_words.png" />


<div class="text-center" id="fb-root">
  <div class="btn btn-primary" onclick="fbshare()"></div>
</div>

{% block js %}
<script>
    function fbshare(){
        FB.ui({
          method: 'share',
          href: 'http://localhost:8000/',
          picture: '{{MEDIA_URL }}/social/logo_words.png',
          caption: 'Forecast the Future with CASSIE',
          description: 'Forecast future events- earn points for correct predictions!'
        }, function(response){});
    }
</script>
{% endblock js %}

Possible reason is your are trying to serve it from localhost. 可能的原因是您正在尝试从localhost提供服务。 Facebook needs to reach your server/site to pick up information. Facebook需要访问您的服务器/站点以获取信息。

You should test it by deploying somewhere like Heroku or use any tools like https://ngrok.com/ http://localtunnel.me/ etc to expose localhost to outside world. 您应该通过将其部署在Heroku之类的地方进行测试,或者使用https://ngrok.com/ http://localtunnel.me/之类的任何工具将localhost暴露给外界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM