LEXAlForpostl
Мой дом здесь!
- Регистрация
- 21 Май 2008
- Сообщения
- 766
- Реакции
- 228
- Автор темы
- #1
Здравствуйте.
Пишу скрипт, который бы логинился и затем бы постил в Тв. аккаунт через веб интерфейс.
Этап авторизации пройден успешно.
А вот на этапе постинга какие-то грабли.
Ответ сервера:
403 Forbidden: The server understood the request, but is refusing to fulfill it.
1. Авторизиуремся.
2. Загружаем главную, парсим с неё auth_token (здесь косяков нет, проверенно!)
Вот, собственно, сам код постинга:
Пишу скрипт, который бы логинился и затем бы постил в Тв. аккаунт через веб интерфейс.
Этап авторизации пройден успешно.
А вот на этапе постинга какие-то грабли.
Ответ сервера:
403 Forbidden: The server understood the request, but is refusing to fulfill it.
1. Авторизиуремся.
2. Загружаем главную, парсим с неё auth_token (здесь косяков нет, проверенно!)
Вот, собственно, сам код постинга:
PHP:
function send_post ($post, $auth_token){
$html = post_content_xml ('https://twitter.com/i/tweet/create', 'authenticity_token='.$auth_token.'&place_id=&status='.urlencode($post));
$f = fopen("out.txt","w");
fwrite ($f, $html);
fclose ($f);
}
function post_content_xml ($url,$postdata) {
$uagent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36";
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER , array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With: XMLHttpRequest'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_REFERER, "https://twitter.com/");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_COOKIEJAR, "coo.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE,"coo.txt");
$content = curl_exec( $ch );
curl_close( $ch );
return $content;
}
send_post ('Text 2 http://test2.ru ',$auth_token);
Последнее редактирование: