2

我正在编写一个与我的谷歌帐户相关联的脚本。但我一开始就有问题。谷歌阻止了我的日志记录。我收到此错误:

您的浏览器的cookie功能被关闭。请打开它。

这里有一个脚本:

<?php
$email = "login";
$password = "pass";

//curl get
function curl_get( $curl, $url, $cookiefile) {
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" );
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $data = curl_exec($curl);
    return $data;
}

//curl post

function curl_post( $curl, $url, $cookiefile, $post) {
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" );
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $data = curl_exec($curl);
    return $data;
}

//cookie file
$cookiefile = "cookie.txt";

$curl = curl_init( );

//get url to grab GALX & dsh to login
$data = curl_get( $curl, "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&hl=en_US&ltmpl=sso", $cookiefile);


preg_match('/name="GALX"\s*value="(.*?)"/', $data, $galx);

preg_match('/name="dsh" id="dsh"\s*value="(.*?)"/', $data, $dsh);


//login
$data = curl_post( $curl, "https://www.google.com/accounts/ServiceLoginAuth", $cookiefile, "ltmpl=sso&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&service=youtube&uilel=3&dsh=$dsh[1]&ltmpl=sso&hl=en_US&ltmpl=sso&timeStmp=&secTok=&GALX=$galx[1]&Email=$email&Passwd=$password&PersistentCookie=yes&rmShown=1&signIn=Sign+in&asts=");

//auth url
$data = curl_get( $curl, "https://www.google.com/accounts/CheckCookie?continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252Findex&hl=en_US&service=youtube&ltmpl=sso&chtml=LoginDoneHtml", $cookiefile);
echo $data;
?>

Cookie 文件很好,问题可能出在其他地方。

提前感谢您的帮助。米科拉伊。

4

1 回答 1

0

您应该使用 OAuth 使用您的 Google 帐户登录。

这是一个 PHP OAuth 库:http ://code.google.com/p/oauth-php/和项目的 wiki How To page with sample code:http ://code.google.com/p/oauth-php/wiki/消费者指南

于 2013-02-08T09:09:06.533 回答