大家好,我想做的是:
我有一个python上传脚本上传电影,事情是我希望它是动态的,就像我提供了一个txt文件与谷歌登录在其中(像电子邮件:blalbla and密码:blablabla)我希望通过curl登录+获取pythonapi所需的认证代码。在
我阻止的地方是获取授权代码部分(当我们单击“我接受”时,我们需要一次的代码,允许API对你的帐户做一些事情,比如上传)。。我得到以下错误:那是个错误。在
请求格式不正确。我们只知道这些。在
这是我的代码:require "../class/simple_html_dom.php";
$USERNAME = 'iamtherealginger13@gmail.com';
$PASSWORD = '******';
$COOKIEJAR = 'cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEJAR);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_URL,
'https://accounts.google.com/ServiceLogin?hl=en&service=alerts&continue=http://www.google.com/alerts/manage');
$data = curl_exec($ch);
$formFields = getFormFields($data);
$formFields['Email'] = $USERNAME;
$formFields['Passwd'] = $PASSWORD;
unset($formFields['PersistentCookie']);
$post_string = '';
foreach($formFields as $key => $value) {
$post_string .= $key . '=' . urlencode($value) . '&';
}
$post_string = substr($post_string, 0, -1);
curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://gdata.youtube.com&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob&pageId=none&client_id=911313852664-tir6o945mdn2bouorh\
palkecrg23dng9.apps.googleusercontent.com&hl=fr&from_login=1&as=-5df191bb4410a26d&pli=1&authuser=0");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, null);
$result = curl_exec($ch);
echo $result;
// AFFICHE LA PAGE AVEC LE BOUTON ACCEPTER
$formFields = getFormFieldsAccess($result);
$formFields["bgresponse"] = "js_disabled";
$formFields["submit_access"] = "true";
$post_string = '';
foreach($formFields as $key => $value) {
$post_string .= $key . '=' . $value . '&';
}
$post_string = substr($post_string, 0, -1);
echo 'Donneees post : ';
preg_match_all('!https://accounts[\S]+!', $result, $matches);
$all_urls = $matches[0][2];
$all_urls = urldecode(substr($all_urls, 0, -1));
var_dump($all_urls);
curl_setopt($ch, CURLOPT_URL, $all_urls);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_REFERER, 'https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/youtube.upload&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=911313852664-tir6o945mdn2bouorhpalkecr\
g23dng9.apps.googleusercontent.com&access_type=offline&pageId=none');
$result = curl_exec($ch);
echo $result;