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

相关推荐
牧羊人_myr2 分钟前
Maven核心功能与项目构建详解
java·maven
量子物理学21 分钟前
Eclipse Mosquitto 在小内存下怎么修改配置文件
java·服务器·eclipse
程序员鱼皮32 分钟前
让老弟做个数据同步,结果踩了 7 个大坑!
java·后端·计算机·程序员·编程·职场
Iris76142 分钟前
MyBatis一对多关系映射方式
java
程序员清风42 分钟前
滴滴二面:MySQL执行计划中,Key有值,还是很慢怎么办?
java·后端·面试
白鲸开源42 分钟前
3.1.8<3.2.0<3.3.1,Apache DolphinScheduler集群升级避坑指南
java·开源·github
huohaiyu1 小时前
synchronized (Java)
java·开发语言·安全·synchronized
梵得儿SHI1 小时前
Java 工具类详解:Arrays、Collections、Objects 一篇通关
java·工具类·collections·arrays·objects
熊小猿1 小时前
Spring Boot 的 7 大核心优势
java·spring boot·后端
摸鱼的老谭1 小时前
Java学习之旅第二季-13:方法重写
java·学习·方法重写