php curl 获取google 中文简体,Curl google获取客户端API的授权代码

大家好,我想做的是:

我有一个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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值