1 適用可能な関数
Quick Tracking 「行動分析」-「行動インサイト」-「ユーザーインサイト」-「オーディエンス管理」
2 使用プロセス
2.1 アプリケーション ID を取得する
「行動分析」-「オーディエンス管理」 現在のページリンクからアプリケーション ID を取得できます。次の図のボックスで場所を選択するように示されています。
2.2 オーディエンス ID を取得する
マイオーディエンスリストで、オーディエンス名の下にあるコピー [ボタン] をクリックして、オーディエンス ID をコピーできます。
2.3 openapi を使用して人口の詳細を取得する
2.3.1 権限検証
認証基準
API ID と API [シークレット]
注:データは機密情報であるため、メインアカウントでのみ表示されます。具体的な表示場所は次のとおりです。
「管理コンソール」--> 「情報収集」。
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"
}
認証署名
キーでメソッド名とパラメーターをアルファベット順にソートする
/**
* Quick Tracking バックグラウンドマスターアカウントで表示できます
*/
String secret = "abcdef";
/**
* リクエストされるサービスの名前。
*/
String service = "analysis.userGroup.userList";
/**
* 1. URL パラメーターを取得します。例:apiId=abcdef&sign=abcdef&ts=123456。
* 2. キーでソートし、sign を削除します。結果は apiId=abcdef&ts=123456 です。
*/
String queryString = sort("api_id=abcdef&api_ts=123456");
/**
* POST インターフェース、本文の内容
*/
String bodyString = "{
"dataSourceId": "xxxx",
"groupId":"yyyy",
"pageIndex":1,
"pageSize":1000"
}";
String source = service
+ "\n"
+ queryString
+ "\n"
+ bodyString;
注意: 一部のプラグインは、有効化後に追加の設定が必要な場合があります。
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"; // API ID を設定
String apiSecret = "yyyy"; // API シークレットを設定
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"); // データソース ID を設定
body.put("groupId", "yyyy"); // グループ ID を設定
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 リクエスト本文。
* @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",
"Custom user attribute key1":"Attribute value", // カスタムユーザー属性 key1:属性値
"Custom user attribute key2":"Attribute value", // カスタムユーザー属性 key2:属性値
"Custom user attribute key3":"Attribute value", // カスタムユーザー属性 key3:属性値
"Custom user attribute key4":"Attribute value", // カスタムユーザー属性 key4:属性値
......
},
{
"eid":"e002",
"utdid":"ut001,ut002,ut003",
"sys_user_id":"user02",
"Custom user attribute key1":"Attribute value", // カスタムユーザー属性 key1:属性値
"Custom user attribute key2":"Attribute value", // カスタムユーザー属性 key2:属性値
"Custom user attribute key3":"Attribute value", // カスタムユーザー属性 key3:属性値
"Custom user attribute key4":"Attribute value", // カスタムユーザー属性 key4:属性値
......
},
......
],
"traceId":"2e00f4415a6746e2a5870870b1b2784e",
"success":true
}