简体   繁体   English

从外部站点访问Google Apps脚本

[英]Access Google Apps Scripts from an external site

I currently have a website that automates Instagram actions: http://instapromobiz.com . 我目前有一个可以自动执行Instagram操作的网站: http : //instapromobiz.com It is almost all javascript based, with some php to post to databases. 它几乎都是基于javascript的,其中一些php可以发布到数据库。 Users login and an entry is created in a mySQL database, containing their username and how many credits they have (1 credit = 1 action). 用户登录并在mySQL数据库中创建一个条目,其中包含他们的用户名以及他们拥有多少个积分(1个积分= 1个动作)。 Then users add tags and press start, then the javascript makes requests via Instagrams API, and ajax+php is used to update their database. 然后用户添加标签并按开始,然后javascript通过Instagrams API发出请求,而ajax + php用于更新其数据库。

The issue is that when the user leaves the page, or even refreshes it, the script will stop. 问题是,当用户离开页面甚至刷新页面时,脚本将停止。 Otherwise it will run forever. 否则它将永远运行。

I have a javascript file that contains all the functions needed to run the script until the user stops it. 我有一个javascript文件,其中包含运行脚本直到用户停止脚本所需的所有功能。

My question is, can I use Google Apps Scripts to host this .js file so that when the user leaves the page the script continues to run. 我的问题是,我可以使用Google Apps脚本托管此.js文件,以便在用户离开页面时脚本继续运行。 I've uploaded the code and published it, but I can't figure out how to access it from an external website. 我已经上传并发布了代码,但是我不知道如何从外部网站访问它。

node.js is out of the question, and I'd rather not convert the whole site to php(I don't know php well) and a cron wont work because of all the javascript. node.js是不可能的,我宁愿不将整个站点转换为php(我不太了解php),并且由于所有的javascript,cron无法正常工作。

Any help would be great, thanks! 任何帮助将是巨大的,谢谢!

Apps Script is going to be limited to a 5 minute execution time. Apps脚本的执行时间将限制为5分钟。 You could create time based triggers to contend with that functionality to some extent, but the script will stop 5 minutes after being invoked. 您可以创建基于时间的触发器以在某种程度上与该功能抗衡,但是脚本将在调用后5分钟停止。

If you still think Apps Script is a good fit, you would just need to deploy your script as a web app , and utilize a doGet(event) function or a doPost(event) function to receive the request from your external application. 如果您仍然认为Apps Script很合适,则只需将脚本部署为Web应用程序 ,并利用doGet(event)函数或doPost(event)函数从外部应用程序接收请求。 If you need to return content, there is ContentService to help facilitate that part of the process. 如果您需要返回内容,可以使用ContentService来帮助简化该过程。

To maintain the different data points for each user, you will need to utilize ProertiesService.getUserProperties() , to store persistent string values for each user. 要为每个用户维护不同的数据点,您将需要利用ProertiesService.getUserProperties()来存储每个用户的持久字符串值。

The other part of Apps Script that may come into play with your Javascript, is that Apps Script uses caja sanitization for javascript (just something to be mindful of, if you run into issues). 可能与您的Javascript一起使用的Apps Script的另一部分是,Apps Script使用针对Javascript的caja清理(如果遇到问题,请注意)。

If you MUST defeat the execution time problem in google apps script. 如果您必须克服Google Apps脚本中的执行时间问题。 You can monitor the execution time and at a certain point before time expires invoke the script recursively and pass it the parameter of wherever it left off. 您可以监视执行时间,并在时间到期之前的某个时间点以递归方式调用脚本,并向该脚本传递上次中断的位置的参数。

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

相关问题 如何使用 Google Apps 脚本访问外部电子表格中的数据 - How to access data from an external spreadsheet with Google Apps Script Email 来自 Google Apps Scripts 的过滤结果 - Email the filter results from Google Apps Scripts 链接函数如何访问Google Apps脚本中的表单数据? - How can chained functions access form data in Google Apps Scripts? 部署为网络应用程序的两个Google应用程序脚本之间的localStorage访问 - localStorage access between two google app scripts deployed as web apps 运行 2 个 Google Apps 脚本 - Run 2 Google Apps scripts 如何从跨源站点中的谷歌应用程序脚本 webapp 访问相机? - How to access camera from google apps script webapp framed in a cross origin site? Google小工具和外部脚本 - Google Gadgets and external scripts 在Google文档中访问Google Apps脚本脚本 - accessing Google Apps Scripts scripts in google docs 如何在Google Apps脚本Google Docs Extension中包括大型外部样式表和脚本 - How to include a large external stylesheet and script in Google Apps Scripts Google Docs Extension 请求 Google Apps 脚本实现从 Postman 开始工作,但不从 javascript 开始工作 - Request to Google Apps Scripts Implementation works from Postman but not from javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM