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

相关推荐
St_rive5 小时前
Page Object设计模式
java·开发语言·设计模式
风流 少年6 小时前
Spring AI 2.0:SSE
java·人工智能·spring
凤山老林6 小时前
精细化流量治理:Spring Boot 动态特性开关与灰度发布体系
java·spring boot·后端
Aphelios3809 小时前
一次锁内网络IO引发的Tomcat线程池“饿死”事故
java·开发语言·spring boot·elasticsearch·tomcat·网络io阻塞·线程池耗尽
不可求~9 小时前
C++ std::string_view 不是字符串:从悬空引用到安全用法
java·开发语言·c++
Lam Tang9 小时前
APS 系列文章10
java·代理模式
考虑考虑10 小时前
Excel导入时产生特殊字符处理
java·后端·java ee
Scabbards_10 小时前
面试Leetcode - Heap 堆
java·leetcode·面试
程序员清风10 小时前
专业再升级!程序员专属显示器明基RD280UG上手实测!
java·后端·面试
我命由我1234512 小时前
RxJava - 冷数据流与热数据流
android·java·java-ee·android studio·rxjava·android-studio·android runtime