2011-05-23 38 views
2

你好,我需要以某种方式从登录,卷曲,并得到会议

http://www.google.com/trends?q=lingerie+&ctab=0&geo=id&date=all&sort=0

或更好

http://www.google.com/insights/search/#q=lingerie&geo=ID&cmpt=q

,所以我发现,我们随着时间的推移顶部区域的兴趣和利益必须登录才能输出数据任何人都可以举例说明我们的Google用户名和密码吗?也许使用curl来导出数据?否则

感谢您寻找在

亚当·拉马丹

+0

是否谷歌甚至有趋势/搜索见解的API?据我所见,API中唯一可用的google洞察就是youtube的见解。如果有这样的API,请提供链接? – Niklas 2011-06-05 16:47:52

+0

没有..但有一个可下载的CSV。而且它可以在我们登录时下载(请参阅google auth文章)。多数民众赞成的问题,我不知道如何使用卷曲发送像“你好,这是我即时登录让我下载.CSV文件”。 – 2011-06-05 17:53:40

回答

5

只是要快了,我用我的xhttp class这是一个卷曲的包装,我觉得代码非常容易。

<?php 

header('content-type: text/plain'); 

// Set account login info 
$data['post'] = array(
    'accountType' => 'HOSTED_OR_GOOGLE', // indicates a Google account 
    'Email'  => '', // full email address 
    'Passwd'  => '', 
    'service'  => 'trendspro', // Name of the Google service 
    'source'  => 'codecri.me-example-1.0' // Application's name, e.g. companyName-applicationName-versionID 
); 

$response = xhttp::fetch('https://www.google.com/accounts/ClientLogin', $data); 

// Test if unsuccessful 
if(!$response['successful']) { 
    echo 'response: '; print_r($response); 
    die(); 
} 

// Extract SID 
preg_match('/SID=(.+)/', $response['body'], $matches); 
$sid = $matches[1]; 

// Erase POST variables used on the previous xhttp call 
$data = array(); 

// Set the SID in cookies 
$data['cookies'] = array(
    'SID' => $sid 
); 

$response = xhttp::fetch('http://www.google.com/insights/search/overviewReport?q=lingerie&geo=ID&cmpt=q&content=1&export=1', $data); 

// CSV data in the response body 
echo $response['body']; 

?> 

结果是:http://codecri.me/apps/test/test.google.trends.php 但我不知道,如果结果是你在找什么。

+1

这是史诗。 :D – 2011-06-09 17:20:44

+0

@Adam我的答案是否有缺失?我希望得到我的第一个赏金哈哈。 – Arvin 2011-06-12 15:55:27

+0

nope,你最好的伴侣。 btw为什么25?我仍然不知道这个东西是如何工作的。大声笑。不管怎样,谢谢! – 2011-06-14 17:16:24

0

的卷发男子页的东西介绍如何提供用户名和密码。你尝试过-u旗帜吗?

-u/- 用户 指定用于服务器认证的用户名和密码。覆盖-n/- netrc和--netrc-可选。

If you just give the user name (without entering a colon) curl will prompt for a password. 

    If you use an SSPI-enabled curl binary and do NTLM authentication, you can force curl to pick up the user name and password from your environment by simply specifying a single colon with this option: "-u :". 

    If this option is used several times, the last one will be used. 
1

自2012年4月谷歌改变了它的身份验证策略,请编辑阿尔文的代码如下:

// Extract Auth 
preg_match('/Auth=(.+)/', $response['body'], $matches); 
$auth = $matches[1]; 

// Erase POST variables used on the previous xhttp call 
$data = array(); 

// Set the Authorization header 
$data['headers'] = array(
    'Authorization' => 'GoogleLogin auth='.$auth 
);