如何在谷歌洞察中使用谷歌授权下载cvs文件-必须使用zend类,而不是其他php方式(zend_gbase等)


How download cvs file with google authorization in google insights - have to use zend classes and not other php ways (zend_gbase etc.. )

如何在谷歌趋势服务中使用谷歌授权下载cvs文件-必须使用zend框架类,而不是其他php方式。

谢谢,

Yosef

这可能是您所需要的。您需要在$email$passwd变量中输入您的Google用户名和密码,并设置自动加载器或需要ZF类。

参考文献:Zend_Gdata_ClientLogin和ClientLogin

// setup the autoloader first or require used classes
// using the example code in the example to get auth tokens
try {
    $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'xapi', $httpClient);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
    echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "'n";
    echo 'Token ID: ' . $cre->getCaptchaToken() . "'n";
} catch (Zend_Gdata_App_AuthException $ae) {
    echo 'Problem authenticating: ' . $ae->exception() . "'n";
}
// extract authentication tokens from response body
$ck_count = preg_match_all('/^(.+)=(.+)$/m', $client->getLastResponse()->getBody(), $cookies);
// build a new http client
$auth = new Zend_Http_Client('http://www.google.com/trends/viz?q=facebook&graph=all_csv&sa=N');
for ($i = 0; $i < $ck_count; $i++) {
    // authenticate it using the provided tokens as cookies
    $auth->setCookie($cookies[1][$i], $cookies[2][$i]);
}
// make the request and dump cvs data
Zend_Debug::dump($auth->request()->getBody());

给定输出(为简洁起见,截断):

facebook, facebook (std error)
1.00, 0%

Week, facebook, facebook (std error)
Jan 4 2004, 0, >10%
Jan 11 2004, 0, >10%
Jan 18 2004, 0, >10%
Jan 25 2004, 0, >10%
Feb 1 2004, 0, >10%
Feb 8 2004, 0, >10%
Feb 15 2004, 0, >10%
Feb 22 2004, 0, >10%
Feb 29 2004, 0, >10%