English 中文(简体)
利用谷歌图书服务器与PHP
原标题:Accessing Google Bookmarks server side with PHP

我曾使用过我的谷歌图书标识,服务器与这一PHP代码相配套:

$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, "https://www.google.com/bookmarks/?output=rss");
curl_setopt($curlObj, CURLOPT_USERPWD, "[email protected]:mypassword");
curl_setopt ($curlObj, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curlObj);
echo $response;
curl_close($curlObj);

以前,根据上述法典,我会看到XML的饲料。

Now it shows "302 Your document has moved. Click Here". The link takes me to a login page.

任何想法?

感谢。

最佳回答

这种授权已不再有效。 页: 1

例如:

<?
$USERNAME =  aaa ;
$PASSWORD =  bbb ;

$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, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
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=bookmarks&continue=http://www.google.com/bookmarks );
$data = curl_exec($ch);

$formFields = getFormFields($data); // my code to get form fields, ask if you want it

$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);
$info = curl_getinfo($ch);
// echo var_dump($info);
if ($info[ url ]=="https://accounts.google.com/ServiceLoginAuth")
    {
      die("Login failed");
    var_dump($result);
 } else {
    curl_setopt($ch, CURLOPT_URL,  http://www.google.com/bookmarks/?output=rss );
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, null);

    $result = curl_exec($ch);

    var_dump($result);
}

function getFormFields($data)
{
    if (preg_match( /(<form id=.?gaia_loginform.*?</form>)/is , $data, $matches)) {
        $inputs = getInputs($matches[1]);

        return $inputs;
    } else {
        die( didnt find login form );
    }
}

function getInputs($form)
{
    $inputs = array();

    $elements = preg_match_all( /(<input[^>]+>)/is , $form, $matches);

    if ($elements > 0) {
        for($i = 0; $i < $elements; $i++) {
            $el = preg_replace( /s{2,}/ ,    , $matches[1][$i]);

            if (preg_match( /name=(?:[" ])?([^" s]*)/i , $el, $name)) {
                $name  = $name[1];
                $value =   ;

                if (preg_match( /value=(?:[" ])?([^" s]*)/i , $el, $value)) {
                    $value = $value[1];
                }

                $inputs[$name] = $value;
            }
        }
    }

    return $inputs;
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签