如何在谷歌趋势服务中下载具有谷歌授权的 cvs 文件 - 必须使用 zend 框架类而不是其他 php方式。
谢谢,
约瑟夫
这可能是你需要的。您需要在$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%