D
D
Dmitry2018-08-17 13:10:45
PHP
Dmitry, 2018-08-17 13:10:45

Why doesn't the bot work with curl?

Hello, I am training to write a bot, I want to write a bot that will log in to Twitter.com and show the news feed.
I wrote the code that I will provide below, the bottom line is that I send the correct token, login and password too - but twitter gives out "The entered username and password do not match those stored in our database. Please check the correctness of the entered data and try again."
The code:

<?php

  function request($url, $postdata = null, $cookiefile = 'twitter/cookie.txt')
  {
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0');

    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $cookiefile);

    if ($postdata)
    {
      curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    }

    $html = curl_exec($ch);
    curl_close($ch);
    return ($html);
  }

  file_put_contents('tmp/cookie.txt', '');

  $post = [
    'session[username_or_email]'=> 'login',
    'session[password]'				=> 'password,
    'authenticity_token'			=> 'f4d8cfaac656c87486a3abc9ff1f29e50f34d31b',
    'ui_metrics'					=> '',
    'scribe_log'					=> '',
    'redirect_after_login'			=> '',
    'authenticity_token'			=> 'f4d8cfaac656c87486a3abc9ff1f29e50f34d31b',
    'remember_me'					=> '1',
  ];

  $html = request('https://twitter.com/sessions', $post);
  echo $html;

?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question