facebook回传

1、引入依赖

首先引入依赖,这里我使用API v14.0:

XML 复制代码
        <dependency>
            <groupId>com.facebook.business.sdk</groupId>
            <artifactId>facebook-java-business-sdk</artifactId>
            <version>14.0.0</version>
        </dependency>

2、修改配置文件

在application.yml或properties中引入 pix_id 和 access_token:

XML 复制代码
facebook.pix.id=xxxxxxx
facebook.access.token=xxxxxxxxxxx

3、Controller文件

编写接口:

java 复制代码
    @PostMapping("/facebook")
    public CommonResult<String> returnToPlat(@RequestBody @Valid InvestParam investParam) {
        service.returnToPlat(investParam);
        return CommonResult.ok();
    }

4、Service文件

java 复制代码
    @Value("${facebook.pix.id}")
    private String pixId;

    @Value("${facebook.access.token}")
    private String accessToken;

    @Override
    public void returnToPlat(InvestParam investParam) {

        
        APIContext context = new APIContext(accessToken).enableDebug(true);
        context.setLogger(System.out);

        UserData userData = new UserData()
                .fbc(investParam.getExposureId());

        BigDecimal decimal = investParam.getFee().divide(new BigDecimal(100));
        Float fee = Float.valueOf(String.valueOf(decimal));

        CustomData customData = new CustomData()
                .currency("usd")
                .value(fee);

        Event purchaseEvent = new Event();
        purchaseEvent.eventName(investParam.getEventType())
                .eventTime(System.currentTimeMillis() / 1000L)
                .userData(userData)
                .customData(customData)
                .actionSource(ActionSource.website);

        EventRequest eventRequest = new EventRequest(pixId, context);
        eventRequest.addDataItem(purchaseEvent);

        try {
            EventResponse response = eventRequest.execute();
            investOperate.setResult(response.toString());
            this.save(investOperate);
            System.out.println(String.format("Standard API response : %s ", response));
        } catch (APIException e) {
            e.printStackTrace();
        }
    }

回传接口API官方文档:

https://developers.facebook.com/docs/marketing-api/conversions-api/using-the-api

相关推荐
TT哇30 分钟前
【Java EE初阶】计算机是如何⼯作的
java·redis·java-ee
Fireworkitte7 小时前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
weixin-a153003083167 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
DCTANT8 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
Touper.8 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
黄雪超8 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice8 小时前
对象的finalization机制Test
java·开发语言·jvm
望获linux9 小时前
【实时Linux实战系列】CPU 隔离与屏蔽技术
java·linux·运维·服务器·操作系统·开源软件·嵌入式软件
JosieBook9 小时前
【Java编程动手学】使用IDEA创建第一个HelloJava程序
java·开发语言·intellij-idea
Thomas_YXQ9 小时前
Unity3D DOTS场景流式加载技术
java·开发语言·unity