简体   繁体   English

与Google+共享不起作用

[英]Sharing to Google+ doesn't work

I'm creating a cross-platform mobile app using HTML + JS + CSS. 我正在使用HTML + JS + CSS创建一个跨平台的移动应用程序。 I want to share a custom text in Google+. 我想在Google+中共享自定义文本。 I have the following code segments: 我有以下代码段:

        <button class="demo g-interactivepost"
            data-clientid="xxx.apps.googleusercontent.com"
            data-contenturl="https://developers.google.com/+/web/share/interactive"
            data-calltoactionlabel="INVITE"
            data-calltoactionurl="http://developers.google.com/+/web/share/interactive?invite=true"
            data-cookiepolicy="single_host_origin"
            data-prefilltext="I just tried the quiz. Check it out for yourself!">
            Google+
        </button>

<script type="text/javascript">
    (function() {
        var po = document.createElement('script');
        po.type = 'text/javascript';
        po.async = true;
        po.src = 'https://apis.google.com/js/client:plusone.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(po, s);
    })();
</script>

Please note that I have already created a Google+ App, and got my client id, though I didn't do any changes to the app, cause I don't know whether I need to enable or disable something on Google Developer Console. 请注意,尽管我没有对应用程序进行任何更改,但我已经创建了一个Google+应用程序并获得了我的客户ID,因为我不知道我是否需要在Google Developer Console上启用或禁用某些功能。 On the other hand, in the above code segment I have replaced the "xxx" part with my client ID. 另一方面,在上面的代码段中,我用我的客户ID替换了“ xxx”部分。 The point is that when I press the button, it opens the the sign-in page from Google and after successful sign in, this page displays: http://prntscr.com/3oa1j7 But at that point wherever I press, I get just a blank screen. 关键是,当我按下按钮时,它将打开Goog​​le的登录页面,成功登录后将显示以下页面: http : //prntscr.com/3oa1j7但是,无论何时我按一下,我都会得到黑屏。 If anyone can help me fix the problem, I would be glad. 如果有人可以帮助我解决问题,我将很高兴。

Your code is working for me, so the most likely cause for your issue is your client configuration, specifically the authorized Javascript origins field. 您的代码对我有用,因此最可能引起问题的原因是您的客户端配置,特别是授权的Javascript origins字段。 If you use the example client IDs, nothing will work. 如果使用示例客户端ID,则将无效。 You must configure your own client from https://console.developers.google.com 您必须从https://console.developers.google.com配置自己的客户端

First, make sure that the script is correctly loading your profile. 首先,请确保脚本正确加载了您的配置文件。 After you have accessed the site, you should see the toast for your profile appear in the bottom. 访问该网站后,您应该会在底部看到您的个人资料吐司。 If this is working, then your client ID is valid in the button. 如果这样做有效,则您的客户ID在该按钮中有效。

Next, make sure that you have added your site to the authorized origins of your project. 接下来,确保已将站点添加到项目的授权来源。 HTTP vs HTTPS matters. HTTP vs HTTPS很重要。 The port for your server matters (if it's not the standard port for your preferred protocol). 服务器的端口很重要(如果它不是首选协议的标准端口)。 Double check that everything matches up, this is the most likely cause. 仔细检查所有内容是否匹配,这是最可能的原因。 Because you're only using Javascript, the authorized origins is the only field you need to update. 因为您仅使用Javascript,所以授权的来源是唯一需要更新的字段。

Open up the developer tools in your browser and check the Javascript console for information about why the post is not rendering. 在浏览器中打开开发人员工具,并检查Javascript控制台以获取有关为何不呈现帖子的信息。 If point 1. doesn't work, please share additional information about the error you're seeing. 如果第1点不起作用,请分享有关您看到的错误的其他信息。

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

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