WeChat - Token Request And Data Retrieve

WeChat provides a convenient data API for accessing the data generated from verified official(VO) accounts. Such data is crucially important for the study of user behaviours for WeChat.This post briefly illustrates the simplest procedure to access data API.

Preparation

What is needed is the appID and appSecret, which are unique for each VO account.

Coding

ACCESS_TOKEN

Get request with the appid and appsecret as parameters

curl -d "appid=APPID&appsecret=APPSECRET" -G https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential

Request for Data

Post request with JSON parameter begin_date and end_date specifying the period of data to be return

curl https://api.weixin.qq.com/datacube/getusersummary?access_token=bAfxdRaG5SOrueZ_C9zBNlEqU4ykezgmNAoIhB0Y1LbmBQtl6FWvUDtncM2TDAVfjdCe99raXwRZoKgUhLMiELHkg0RVM3pxhxftt93PQu9BW9SDen-4s9ZjohHLlZ32BVBaAGAUOU \
  -d '{"begin_date": "2014-12-02","end_date": "2014-12-07"}' \
  -H 'Content-Type: application/json' 

Reference