php - 使用curl登录并获取 session

标签 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来导出数据?或者其他东西

感谢您的关注

亚当·拉马丹

最佳答案

为了快速起见,我使用了我的 xhttp class这是一个curl 包装器,我认为代码很容易理解。

<?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 但我不确定结果是否是您想要的。

关于php - 使用curl登录并获取 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6101151/

相关文章:

php - 使用 cURL 编译 PHP 失败

PHP for循环不进入循环

javascript - 在页面上多次使用时 WordPress 短代码的唯一 ID?

c# - 是否记录了 ExecuteMso 的命令代码?

c# - 以编程方式将文件 checkin TFS 获得的数量超出预期

ruby - Sinatra 使用 curl 丢失了部分查询字符串

api - 如何排查与 Google Adsense API 的连接问题

php - 为什么我输入此查询后我的 PHP MYSQL 查询无法工作/运行?

php - 无法将数据插入多个数据库 Codeigniter(MongoDB 和 MySQL)

api - 如何通过 TCPIP 远程控制三星智能电视