- 登錄到谷歌
- 從谷歌趨勢
下載CSV數據我成功(1 )而不是(2)。我得到恢復,從谷歌的授權令牌,並正與後續請求趨勢發送它,但儘管如此谷歌隨後會返回一個錯誤:「您必須先登錄輸出從谷歌趨勢的數據」:
// http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
$data = array(
'accountType' => 'GOOGLE',
'Email' => '[email protected]',
'Passwd' => 'my.password',
'service' => 'trendspro',
'source' => 'company-application-1.0'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPAUTH, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
// We now have an authorization-token
$headers = array(
"Authorization: GoogleLogin auth=" . $matches[1],
"GData-Version: 3.0"
);
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/trends/viz?q=MSFT&date=2011-2&geo=all&graph=all_csv&sort=0&sa=N");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, false);
$csv = curl_exec($ch);
curl_close($ch);
// Returns : "You must be signed in to export data from Google Trends"
// Expected: CSV data stream
print_r($csv);
出於某種原因,我發送給Google趨勢的身份驗證令牌沒有被接受或忽略。我不知道會發生什麼,因爲沒有提供額外的錯誤信息。
有沒有人看到我做錯了什麼?如果你能得到它的工作,這意味着谷歌正在返回CSV數據,那麼賞金是你的,我們都擁有一個遲到的聖誕禮物:-)
所以我想通了這個問題無關與捲曲。我做的是:
SID=DQAAAMUAAADMqt...aYPaYniC_iW LSID=DQAAAMcAAACI5...YDTBDt_xZC9 Auth=DQAAAMgAAABm8...trXgqNv-g0H
- 我複製返回身份驗證令牌:DQAAAMgAAABm8 ... trXgqNv-g0H
- 我發送郵件使用郵遞員Chrome擴展GET請求http://www.google.com/trends/viz?q=MSFT&date=2011-2&geo=all&graph=all_csv&sort=0&sa=N使用標題:
GData-Version: 3.0 Authorization: GoogleLogin auth=DQAAAMgAAABm8...trXgqNv-g0H
- 我得到恢復:
標題:
Date: Tue, 27 Dec 2011 00:17:20 GMT Content-Encoding: gzip Content-Disposition: filename=trends.csv Content-Length: 97 X-XSS-Protection: 1; mode=block Server: Google Trends X-Frame-Options: SAMEORIGIN Content-Type: text/csv; charset=UTF-8 Cache-Control: private
數據:
You must be signed in to export data from Google Trends
換句話說,我要送頭由谷歌在http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html定義,但沒有運氣得到合理的回報。 Interwebs上有關於此的* no *信息。誰知道問題在這裏?
你在這裏檢查http://stackoverflow.com/questions/4986758/oauth-google-trends-download-csv-file – Pateman 2011-12-26 17:34:57
感謝您的提示。您的鏈接將我帶到http://stackoverflow.com/questions/1656446/download-csv-from-google-insight-for-search,但這也不能解決問題。我正在按照那裏的解釋做,但沒有運氣,我看不到我在做什麼錯... – Pr0no 2011-12-26 19:47:08
不知道這是否有幫助,但有一個人使用cURL訪問HTTPS網站時遇到問題,他的問題在這裏解決:http://stackoverflow.com/questions/316099/cant-connect-to-https-site-using-curl-returns-0-length-content-instead-what-c – Pateman 2011-12-26 20:00:22