1 适用功能
Quick Tracking「行为分析」-「行为洞察」-「用户洞察」-「人群管理」
2 使用流程
2.1 获取应用ID
「行为分析」-「人群管理」当前页面链接中可获取应用ID,如下图框选位置展示:
2.2 获取人群ID
我的人群列表中可点击人群名称下复制按钮进行复制人群ID
2.3 使用openapi获取人群明细
2.3.1 权限校验
鉴权依据
API ID、API Secret
注:由于数据敏感,所以只在主账号中可见,具体展示位置为:
“管理控制台”--〉“采集信息”
URL参数
http://xxx.yyy.com/api/{service}?api_id=abcdef&api_sign=abcdef&api_ts=123456
参数名 | 描述 | 备注 |
api_id | API ID | Quick Tracking后台主账号可查看 |
api_sign | 签名 | 具体逻辑见“鉴权签名” |
api_ts | 时间戳 | 毫秒 |
http://xxx.yyy.com/ | 前台页面管理域名 | 登录Quick Tracking后浏览器前台展示域名 |
body参数
{
"dataSourceId": "xxxx",
"groupId":"yyyy",
"pageIndex":1,
"pageSize":1000"
}
鉴权签名
方法名 + 参数按照key进行字母排序
/**
* Quick Tracking后台主账号可查看
*/
String secret = "abcdef";
/**
* 当前要请求的服务名
*/
String service = "analysis.userGroup.userList";
/**
* 1.获取url参数,如apiId=abcdef&sign=abcdef&ts=123456
* 2.按照key排序,移除sign,结果apiId=abcdef&ts=123456
*/
String queryString = sort("api_id=abcdef&api_ts=123456");
/**
* POST接口,body内容
*/
String bodyString = "{
"dataSourceId": "xxxx",
"groupId":"yyyy",
"pageIndex":1,
"pageSize":1000"
}";
String source = service
+ "\n"
+ queryString
+ "\n"
+ bodyString;
用API Secret对source进行加密
String sign = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, secret).hmacHex(source);
sign = 1cfc10a297397e91f1e50e1f41ac24b8c45fd53d
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.3.0</version>
</dependency>
package com.alibaba.dt.atm.apsara.init;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
* @author mingpeng.spc
* @date 2022/01/07
*/
public class OpenApiControllerTest {
private static final MediaType APPLICATION_JSON = MediaType.parse("application/json; charset=utf-8");
private final static Logger LOGGER = LoggerFactory.getLogger(OpenApiControllerTest.class);
public static void main(String[] args) {
String url = "https://{domain}/api/";
String service = "analysis.userGroup.userList";
String apiId = "xxxx";
String apiSecret = "yyyy";
LOGGER.info("current time = {}", System.currentTimeMillis());
/**
* 构造url参数
*/
String query = new StringBuilder()
.append("api_id=").append(apiId)
.append("&")
.append("api_ts=").append(System.currentTimeMillis())
.toString();
/**
* 构造body参数
*/
JSONObject body = new JSONObject();
body.put("dataSourceId", "xxxx");
body.put("groupId", "yyyy");
body.put("pageIndex", 1);
body.put("pageSize", 100);
String bodyString = body.toJSONString();
/**
* service
* query
* body
*/
StringBuilder valueToDigest = new StringBuilder()
.append(service)
.append("\n")
.append(query)
.append("\n")
.append(bodyString);
String sign = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, apiSecret).hmacHex(valueToDigest.toString());
Response response = null;
try {
response = post(url + service + "?" + query + "&api_sign=" + sign, bodyString);
System.out.println(response.body().string());
} catch (Exception e) {
LOGGER.info("invoke post error", e);
} finally {
if (response != null) {
response.close();
}
}
}
/**
* HTTP Post
*
* @param url URL
* @param body 请求body
* @return
*/
private static Response post(String url, String body) throws IOException {
LOGGER.info("http post start, url = {}, body = {}", url, body);
RequestBody requestBody = RequestBody.create(APPLICATION_JSON, body);
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(300, TimeUnit.SECONDS)
.writeTimeout(300, TimeUnit.SECONDS)
.readTimeout(300, TimeUnit.SECONDS).build();
Response response = client.newCall(request).execute();
LOGGER.info("http post success");
return response;
}
}
2.3.2 数据获取
请求:
名称 | 类型 | 是否必须 | 描述 |
dataSourceId | String | 必填 | 应用ID |
grportId | String | 必填 | 人群ID |
pageIndex | Integer | 必填 | 页码 |
pageSize | Integer | 必填 | 分页,最大50000 |
{
"dataSourceId": "xxxx",
"groupId":"yyyy",
"pageIndex":1,
"pageSize":1000"
}
返回:
{
"code":200,
"msg":"SUCCESS",
"sCode":200,
"sMsg":"SUCCESS",
"data":[
{
"eid":"e001",
"utdid":"u001,u002,u003",
"sys_user_id":"user01",
"客户自定义用户属性key1":"属性值",
"客户自定义用户属性key2":"属性值",
"客户自定义用户属性key3":"属性值",
"客户自定义用户属性key4":"属性值",
......
},
{
"eid":"e002",
"utdid":"ut001,ut002,ut003",
"sys_user_id":"user02",
"客户自定义用户属性key1":"属性值",
"客户自定义用户属性key2":"属性值",
"客户自定义用户属性key3":"属性值",
"客户自定义用户属性key4":"属性值",
......
},
......
],
"traceId":"2e00f4415a6746e2a5870870b1b2784e",
"success":true
}
文档内容是否对您有帮助?