用curl登录并获取会话

Ada*_*han 2 php api curl

你好,我需要以某种方式获得最高的区域利益和兴趣随着时间的推移

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

所以我发现我们必须登录导出数据任何人都可以用我们的谷歌用户名和密码给我一个例子吗?也许使用curl导出数据?或者是其他东西

谢谢你的关注

亚当拉马丹

Arv*_*vin 5

为了快速了解它,我使用了我的xhttp类,这是一个卷曲包装器,我认为代码很容易遵循.

<?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'];

?>
Run Code Online (Sandbox Code Playgroud)

结果如下:http://codecri.me/apps/test/test.google.trends.php 但我不确定结果是否符合您的要求.