Created
November 25, 2014 21:22
-
-
Save 5l/429fc06287c9a0ab3561 to your computer and use it in GitHub Desktop.
Twitterのパスワード変更
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$id = "screen_name"; | |
$pass = "password"; | |
$newpass = "newpassword"; | |
//authenticitytokenの取得 | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://twitter.com"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie"); | |
$html = curl_exec($ch); | |
preg_match('#<input type="hidden" value="(.+?)" name="authenticity_token"/>#', $html, $match); | |
$post = array( | |
"session[username_or_email]" => $id, | |
"session[password]" => $pass, | |
"authenticity_token" => $match[1], | |
); | |
//ログイン | |
curl_setopt($ch, CURLOPT_URL, "https://twitter.com/sessions"); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_exec($ch); | |
$change = array( | |
"authenticity_token" => $match[1], | |
"current_password" => $pass, | |
"user_password" => $newpass, | |
"user_password_confirmation" => $newpass, | |
"_method" => "PUT", | |
); | |
//パスワード変更 | |
curl_setopt($ch, CURLOPT_URL, "https://twitter.com/settings/passwords/update"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($change)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); | |
curl_exec($ch); | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment