简体   繁体   English

使用来自Canvas的交互式帖子

[英]Using Interactive Posts from Canvas

I am trying to implement Google+ features in a canvas element - 我正在尝试在canvas元素中实现Google+功能-

is it possible to request an interactive post popup without the use of gapi.interactivepost.render()? 是否可以在不使用gapi.interactivepost.render()的情况下请求交互式帖子弹出窗口?

Similarly, is there a way to trigger gapi.auth.authorize() from JS and have it seen as a user-action? 同样,是否有办法从JS触发gapi.auth.authorize()并将其视为用户操作? (as would be seen from a direct click on a link/button). (从直接点击链接/按钮可以看到)。

You can't render the Google+ button within within the canvas, but you can place a div over the HTML canvas and can render the button over the canvas. 您无法在画布内渲染Google+按钮,但可以在HTML画布上放置div,也可以在画布上渲染按钮。 For example: 例如:

HTML for canvas and the button target 用于画布的HTML和按钮目标

<p>
  <div id="canvasPlus" style="position:relative">
    <canvas id="canvas" width="800" height="600"></canvas>
    <div style = "position:absolute; top:20px; left:230px;" id="shareContainer">
      <button id="ipost">Share</button>
    </div>
  </div>
</p>

JavaScript for rendering the button over the canvas 用于在画布上呈现按钮的JavaScript

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

function onPlusOneLoaded(){
  var params = {
    clientid: 'YOUR_CLIENT_ID',
    cookiepolicy: 'single_host_origin',
    scope: 'https://www.googleapis.com/auth/plus.login',
    contenturl: 'https://plus.google.com/pages/',
    calltoactionurl: 'https://plus.google.com/pages/',
    prefilltext: 'Hello Stack Overflow',
  };
  gapi.interactivepost.render('ipost', params);
  drawCanvas();
}

function drawCanvas(){
  var ctx = document.getElementById('canvas').getContext('2d');
  for (var i=0;i<25;i++){
    ctx.fillStyle = "rgba(200,0,0,.5)";
    ctx.fillRect (10 + 10*i, 10 + 10*i, 55, 50);
  }
}
</script>

I'm not sure what you're asking with regards to "seen as a user action" but you can trigger the authorization dialog with an API call such as: 对于“被视为用户操作”,我不确定您要问什么,但是您可以使用以下API调用触发授权对话框:

gapi.auth.authorize({
  client_id: 'YOUR_CLIENT_ID',
  cookiepolicy: 'single_host_origin',
  scope: 'https://www.googleapis.com/auth/plus.login'
});

When you do this you lose the ability to perform over the air installs on Android. 执行此操作时,您将失去在Android上进行空中安装的能力。

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

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