1

I'm logging-in Wordpress account from google app script.

This is my try:

var url='http://www...it/wp-login.php';
var options = {
  "method": "post",
  "payload": {
    "log": "user",
    "pwd": "password",
    "wp-submit": "Login",
    "testcookie":'1',
  },
  "followRedirects": false,
};
var response = UrlFetchApp.fetch(url,options);

I get 200 code, instead of expected 302 code.

Where I get wrong?

Other solutions, such as this, give me 404 error code.

2 Answers2

1

The 200 response code indicates that your request to fetch the desired URL was performed succesfully, while the 302 code means that you are redirected.

The Wordpress login page will redirect you, if your log-in credentials are correct.

In other words - your request is not correct. The sample you are referring to is valid for an ADMIN logging into the ADMIN log-in URL. Is this also your case? Can you log-in manually if you open the URL and use the same credentials as in your Apps Script code?

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • The credentials are correct, because if I manually open the URL and use the same credentials I'm redicted. – Fabio Lucchini Jul 29 '19 at 14:00
  • In this case, given you use "followRedirects": false in your code - this is why you are not being redirected. If, however, you get an error when you enable redirecting and follow the solution to which you referred - there must be something wrong with the way how you implement that solution, rather than the code you provide in this question. – ziganotschka Jul 29 '19 at 20:51
  • Setting "followRedirects": true I get 200 code again, even with wrong username or password. – Fabio Lucchini Jul 29 '19 at 21:09
0

Just went through this in case someone else stumbles upon this question.

Things to check:

wp-submit: "Log In" or "Log+In"

Might need redirect_to field

It didn't work without passing Referer: header (doesn't seem t validate this)

Also you need to handle cookies, wp-login sets wordpress_test_cookie=WP+Cookie+check

  • Do you have a working example per chance? I have put something together for login but it is just giving 200 when I think it should re-direct. – Mike May 30 '23 at 19:59