如何进行身份验证以使用Google脚本登录网站? [英] How to make authentication to log in a website with Google scripts?

查看:153
本文介绍了如何进行身份验证以使用Google脚本登录网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行身份验证,然后使用Google Apps脚本将广告发布到网站上. 计划是这样的:

I want to make an authentication and then post an ad to a website with a Google Apps Script. The plan is like this:

  1. 进行身份验证以通过HTTP post方法登录.
  2. 获取响应并获取所需的cookie.
  3. 发送新的帖子请求,其中包含所需的广告内容和cookie,以使网站将脚本识别为登录用户".

我被困在第一阶段. 我编写了这个脚本:

I'm stuck on the 1st stage. I made this script:

function sendHttpPost() {
   var options =
   {
     "method" : "post",
     "login[email]" : "mihsav76@gmail.com",
     "login[password]" : "testpas"              
   };

   var response = UrlFetchApp.fetch("http://olx.ua/myaccount/", options);
   var sessionDetails = response.getAllHeaders();       
   Logger.log(response.getContentText());
 }

我通过开发者控制台获得的凭据.屏幕截图已随附.

Credentials I got through Developer Console. Screenshot is attached.

HTML代码只是一个初始登录页面.在这个阶段做错了什么?

HTML code which I get from response is just a starting log in page. What is done wrong on this stage?

推荐答案

您要将登录参数作为选项传递给UrlFetchApp,但是您需要将它们作为POST正文中的字段传递.这是通过有效载荷"选项完成的.

You are passing the login parameters as options to UrlFetchApp, but you need to pass them as fields in the POST body. This is done with the 'payload' option.

   var options =
   {
     "method" : "post",
     "payload":{"login[email]" : "mihsav76@gmail.com",
                "login[password]" : "testpas"
               }
   };

请参见此处的文档中的高级参数"表和示例:

See the "advanced parameters" table and examples in the documentation here:

https://开发人员. google.com/apps-script/reference/url-fetch/url-fetch-app#fetchurl-params

这篇关于如何进行身份验证以使用Google脚本登录网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆