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

相关推荐
夜晚回家27 分钟前
「Java基本语法」代码格式与注释规范
java·开发语言
斯普信云原生组37 分钟前
Docker构建自定义的镜像
java·spring cloud·docker
wangjinjin18041 分钟前
使用 IntelliJ IDEA 安装通义灵码(TONGYI Lingma)插件,进行后端 Java Spring Boot 项目的用户用例生成及常见问题处理
java·spring boot·intellij-idea
wtg445241 分钟前
使用 Rest-Assured 和 TestNG 进行购物车功能的 API 自动化测试
java
白宇横流学长1 小时前
基于SpringBoot实现的大创管理系统设计与实现【源码+文档】
java·spring boot·后端
fat house cat_2 小时前
【redis】线程IO模型
java·redis
stein_java2 小时前
springMVC-10验证及国际化
java·spring
weixin_478689763 小时前
C++ 对 C 的兼容性
java·c语言·c++
LUCIAZZZ3 小时前
HikariCP数据库连接池原理解析
java·jvm·数据库·spring·springboot·线程池·连接池
sky_ph3 小时前
JAVA-GC浅析(二)G1(Garbage First)回收器
java·后端