Baidu

Baidu SEM Services Baidu Ranking Services Baidu Map Services

Installation

Add this line to your application's Gemfile:

gem 'baidu'

And then execute:

$ bundle

Or install it yourself as:

$ gem install baidu

Acknowledged

camel命名法,用于request数据格式 snake命名法,用于response数据格式

Rspec

先修改spec/spec_helper.rb


$username = ''
$password = ''
$token = ''

Usage

SEM

require 'baidu'

$auth = Baidu::Auth.new
$auth.username = 'username'
$auth.password = 'password'
$auth.token = 'token'

ss = Baidu::SEM::SearchService.new
res = ss.getKeywordBySearch({:searchWord=>'word',:searchType=>0})
res = ss.getKeywordBySearch({:searchWord=>'word',:searchType=>0},true) #debug=true

Documents

RankingService

方法

getPreview

Request: GetPreviewRequest

属性名 类型 意义 限制 说明
keyWords List String 关键词字面 必填 目前最多输入5个关键词,超过报错。
device int 设备类型 必填 0:PC 目前只支持PC的推广实况,移动推广实况会于近期推出
region int 地域代码 必填 目前支持二级地域,地域对照表详见《地域对照表》
page int 页码 选填 推广实况的页码,从0开始为第一页
display int 数据展现方式 必填 0:html 该字段为预留字段,目前只支持HTML格式的数据返回方式

Response:GetPreviewResponse

属性名 类型 说明
previewInfos List 关键词的推广实况数据(html格式)

ResponseFormat:PreviewInfo

属性名 类型 说明 限制
keyword String 关键词字面 -
data String 使用gzip进行压缩的推广实况的HTML数据, 解压缩之前请将用base64解码,然后gzip解压,解压后再使用utf-8编码转换为String,即为推广实况的实际HTML数据 -

区域代码

地域代码 地域名称

4085    

错误代码

90191801=The request keyword number is zero
90191802=The request keyword number is more than maximum
90191803=The request device code is neither 0(PC) nor 1(MOBILE)
90191804=The request display code is neither 0(HTML) nor 1(Structure)
90191805=The request page number is invalid
90191806=The request region code is invalid
90191807=The Server is too busy to response, please try again later
90191808=Server internal error, please check your request and try again later.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request