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
}
文檔內容是否對您有幫助?