Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program getUserPortrait


May 19, 2021 WeChat Mini Program Development Document


Table of contents


analysis.getUserPortrait

This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. D eveloper tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0

Get portrait distribution data for new or active users of small programs. T he time range supports yesterday, the last 7 days, the last 30 days. Among them, the number of new users is the number of heavy-weight users who first access the small program in the time range, and the number of active users is the number of the out-of-heavy users who have accessed the small program in the time range.

How to call:

  • HTTPS call
  • Cloud calls

HTTPS call

The request address

POST https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait?access_token=ACCESS_TOKEN

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials
begin_date string Is The start date. The format is yyyymmdd
end_date string Is The end date, with the number of days between the start date and the end date limited to 0/6/29, indicates that the last 1/7/30 days of data are queried, with the maximum allowed to be set for yesterday. The format is yyyymmdd

Returns a value

Object

The returned JSON packet

Property Type Description
ref_date string Time range, e.g. "20170611-20170617"
visit_uv_new Object Portrait of a new user
visit_uv Object Active user portrait

visit_uv_new structure of the system

Property Type Description
index number The type of distribution
province Object provinces, such as Beijing, Guangdong, etc
city Object Cities, such as Beijing, Guangzhou, etc
genders Object Gender, including men, women, unknown
platforms Object Terminal type, including iPhone, Android, other
devices Object Model, such as Apple iPhone 6, OPPO R9, etc.
ages Object Age, including 17 years old, 18-24 years old

PROVINCE structure

Attributes type illustrate
id number Attribute value ID
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the city

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of genders

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the platforms

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the devices

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the ages

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

visit_uv structure of the system

Property Type Description
index number The type of distribution
province Object provinces, such as Beijing, Guangdong, etc
city Object Cities, such as Beijing, Guangzhou, etc
genders Object Gender, including male, female, unknown
platforms Object Terminal types, including iPhone, android, others
devices Object Models such as Apple iPhone 6, OPPO R9, etc
ages Object Age, including under 17 years old, 18-24 years old and so on

The structure of the province

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the city

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of genders

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the platforms

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the devices

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

The structure of the ages

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
access_source_visit_uv number The scene accesses uv

An example of requesting data

{
  "begin_date" : "20170611",
  "end_date" : "20170617"
}

Return an example of the data

{
  "ref_date": "20170611",
  "visit_uv_new": {
    "province": [
      {
        "id": 31,
        "name": "广东省",
        "value": 215
      }
    ],
    "city": [
     {
        "id": 3102,
        "name": "广州",
        "value": 78
      }
    ],
    "genders": [
      {
        "id": 1,
        "name": "男",
        "value": 2146
      }
    ],
    "platforms": [
      {
        "id": 1,
        "name": "iPhone",
        "value": 27642
      }
    ],
    "devices": [
      {
        "name": "OPPO R9",
        "value": 61
      }
    ],
    "ages": [
      {
        "id": 1,
        "name": "17岁以下",
        "value": 151
      }
    ]
  },
  "visit_uv": {
    "province": [
      {
        "id": 31,
        "name": "广东省",
        "value": 1341
      }
    ],
    "city": [
     {
        "id": 3102,
        "name": "广州",
        "value": 234
      }
    ],
    "genders": [
      {
        "id": 1,
        "name": "男",
        "value": 14534
      }
    ],
    "platforms": [
      {
        "id": 1,
        "name": "iPhone",
        "value": 21750
      }
    ],
    "devices": [
      {
        "name": "OPPO R9",
        "value": 617
      }
    ],
    "ages": [
      {
        "id": 1,
        "name": "17岁以下",
        "value": 3156
      }
    ]
  }
}

Cloud calls

Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.

The interface method

openapi.analysis.getUserPortrait
The permissions for the analysis.getUserPortrait API need to be configured in config.json, details

Request parameters

Property Type The default Required Description
beginDate string Is The start date. The format is yyyymmdd
endDate string Is The end date, with the number of days between the start date and the end date limited to 0/6/29, indicates that the last 1/7/30 days of data are queried, with the maximum allowed to be set for yesterday. The format is yyyymmdd

Returns a value

Object

The returned JSON packet

Property Type Description
refDate string Time range, e.g. "20170611-20170617"
visitUvNew Object Portrait of a new user
visitUv Object Active user portrait

The structure of visitUvNew

Property Type Description
index number The type of distribution
province Object provinces, such as Beijing, Guangdong, etc
city Object Cities, such as Beijing, Guangzhou, etc
genders Object Gender, including male, female, unknown
platforms Object Terminal types, including iPhone, android, others
devices Object Models such as Apple iPhone 6, OPPO R9, etc
ages Object Age, including under 17 years old, 18-24 years old and so on

The structure of the province

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the city

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of genders

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the platforms

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the devices

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the ages

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of visitUv

Property Type Description
index number The type of distribution
province Object provinces, such as Beijing, Guangdong, etc
city Object Cities, such as Beijing, Guangzhou, etc
genders Object Gender, including male, female, unknown
platforms Object Terminal types, including iPhone, android, others
devices Object Models such as Apple iPhone 6, OPPO R9, etc
ages Object Age, including under 17 years old, 18-24 years old and so on

The structure of the province

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the city

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of genders

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the platforms

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the devices

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

The structure of the ages

Property Type Description
Id number The property value id
name string The property value name, corresponding to the id. If the property province the returned property value name includes "Guangdong" and so on.
accessSourceVisitUv number The scene accesses uv

An example of requesting data

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.analysis.getUserPortrait({
        beginDate: '20170611',
        endDate: '20170617'
      })
    return result
  } catch (err) {
    return err
  }
}

Return an example of the data

{
  "refDate": "20170611",
  "visitUvNew": {
    "province": [
      {
        "id": 31,
        "name": "广东省",
        "value": 215
      }
    ],
    "city": [
      {
        "id": 3102,
        "name": "广州",
        "value": 78
      }
    ],
    "genders": [
      {
        "id": 1,
        "name": "男",
        "value": 2146
      }
    ],
    "platforms": [
      {
        "id": 1,
        "name": "iPhone",
        "value": 27642
      }
    ],
    "devices": [
      {
        "name": "OPPO R9",
        "value": 61
      }
    ],
    "ages": [
      {
        "id": 1,
        "name": "17岁以下",
        "value": 151
      }
    ]
  },
  "visitUv": {
    "province": [
      {
        "id": 31,
        "name": "广东省",
        "value": 1341
      }
    ],
    "city": [
      {
        "id": 3102,
        "name": "广州",
        "value": 234
      }
    ],
    "genders": [
      {
        "id": 1,
        "name": "男",
        "value": 14534
      }
    ],
    "platforms": [
      {
        "id": 1,
        "name": "iPhone",
        "value": 21750
      }
    ],
    "devices": [
      {
        "name": "OPPO R9",
        "value": 617
      }
    ],
    "ages": [
      {
        "id": 1,
        "name": "17岁以下",
        "value": 3156
      }
    ]
  },
  "errMsg": "openapi.analysis.getUserPortrait:ok"
}