このコードはほぼ完成していますが、問題が発生しました。ピンタレストにオートピン スクリプトを作成していて、ページが読み込まれますが、送信されません :( このスクリプトを完了するには少し助けが必要です。
function login() {
// Create Cookie File
$cookiefile = './pinitcookie.txt';
if (file_exists($cookiefile)) { unlink ($cookiefile); }
//User and pass to Pinterest
$email = '<email>';
$password = '<passowrd>';
// initial login page which redirects to correct sign in page, sets some cookies
$URL = 'https://pinterest.com/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//Create the page for login
$page = curl_exec($ch);
preg_match('/^Set-Cookie:\s*([^;]*)/mi', $page, $m);
//Get Pinterest CSRF token
parse_str($m[1], $cookies);
$token=$cookies['csrftoken'];
// try to find the actual login form
if (!preg_match('/<form id="AuthForm".*?<\/form>/is', $page, $form)) {
die('Failed to find log in form!');
}
$form = $form[0];
// find the action of the login form
if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
die('Failed to find login form url');
}
$URL2 = "https://pinterest.com".$action[1]; // this is our new post url
// find all hidden fields which we need to send with our login, this includes security tokens
$count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
$postFields = array();
// turn the hidden fields into an array
for ($i = 0; $i < $count; ++$i) {
$postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
}
// add our login values
$postFields['email'] = $email;
$postFields['csrfmiddlewaretoken'] = $token;
$postFields['password'] = $password;
$post = '';
// convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
foreach($postFields as $key => $value) {
$post .= $key . '=' . urlencode($value) . '&';
}
$post = substr($post, 0, -1);
curl_setopt($ch, CURLOPT_URL, $URL2);
curl_setopt($ch, CURLOPT_REFERER, $URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$page = curl_exec($ch); // make request
if ($page === FALSE) {
var_dump(curl_getinfo($ch));
}
post_to_pinterest($ch, $token, $cookiefile, $URL);
}
function post_to_pinterest($ch, $token, $cookiefile, $URL) {
#URL3 = "http://www.pinterest.com/pin/create/button/?url=" . rawurlencode(get_permalink($post)) . "&media=" . rawurlencode($url) . "&description=" . rawurlencode(get_the_title($post));
#$URL3 = "http://www.pinterest.com/pin/create/button/?url=http://www.biofects.com&media=http://www.biofects.com/wp-content/uploads/2013/01/Untitled-11.png&description=This is a test";
$URL3 = "http://pinterest.com/pin/create/button/?";
#echo $URL3;
$posting = "board=test&url=http://www.domain.com&media=http://www.domain.com/wp-content/uploads/2013/01/Untitled-11.png&description=This is a test&csrfmiddlewaretoken=$token";
$x="error";
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_URL, $URL3);
//curl_setopt($ch, CURLOPT_REFERER, $URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $posting);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
$pagetopost = curl_exec($ch);// make request
if($x != 'error' & trim($x) != ''){
echo "Curl Try Error".$x;
}
// preg_match('/^Set-Cookie:\s*([^;]*)/mi', $pagetopost, $m);
//Get Pinterest CSRF token
// parse_str($m[1], $cookies);
// $token=$cookies['csrftoken'];
curl_close($ch);
}
login();
これを実現するための助けは素晴らしいでしょう、ありがとう
ところで、私は人々がこれを行っているのを見ていますが、このコードを販売しています。完成したら無料で投稿します:)