facebook回传
2023-12-13 05:24:50
1、引入依赖
首先引入依赖,这里我使用API v14.0:
<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:
facebook.pix.id=xxxxxxx
facebook.access.token=xxxxxxxxxxx
3、Controller文件
编写接口:
@PostMapping("/facebook")
public CommonResult<String> returnToPlat(@RequestBody @Valid InvestParam investParam) {
service.returnToPlat(investParam);
return CommonResult.ok();
}
4、Service文件
@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
文章来源:https://blog.csdn.net/qq_59833893/article/details/134555164
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!