Communicate between AppsScript and Wordpress

2019-07-26 22:48发布

I want a Google Apps Script Webapp to catch the current Username from my Wordpress. I've been working on this a while now but I can't figure it out. I tried it this way - inside wp I run the code:

<?php $current_user = wp_get_current_user(); echo '<div id="username" style="visibility: hidden;">' . $current_user->user_login . '</div>'; ?>

Now I tried to catch the ID content from a google webapp (in an iframe) but I cannot access the parent element. How can I communicate between both?

1条回答
仙女界的扛把子
2楼-- · 2019-07-26 23:04

You can send values to the iframed webapp as parameters.

host page:

<?php $current_user = wp_get_current_user(); echo '<iframe src="https://script.google.com/macros/s/.../exec?name=' . $current_user->user_login . '"></iframe>'; ?>

apps script:

function doGet(e) {  
  var temp = HtmlService.createTemplateFromFile('index');
  temp.name = e.parameters.name;
  return temp.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
查看更多
登录 后发表回答