Skip to content

Instantly share code, notes, and snippets.

@5l
Created November 25, 2014 21:22
Show Gist options
  • Save 5l/429fc06287c9a0ab3561 to your computer and use it in GitHub Desktop.
Save 5l/429fc06287c9a0ab3561 to your computer and use it in GitHub Desktop.
Twitterのパスワード変更
<?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