白鹭egret接入facebook广告

白鹭egret接入facebook广告

问题一:打包后,找不到FBInstant对象

按照文档,在index.html中插入script后,打包上传后找不到FBInstant,查看network后发现压根没有下载fbinstant.7.0.js

<script src="https://www.facebook.com/assets.php/en_US/fbinstant.7.0.js"></script>

解决:需要在template/web/index.html中的header标签中引入

<header>
	<script src="https://www.facebook.com/assets.php/en_US/fbinstant.7.0.js"></script>
</header>

问题二:第一次播放奖励视频后,第二次无法播放

预加载视频后,会实例化一个ad instance,在播放完后该实例会被销毁,因此需要再次初始化一次

public preloadedRewardedVideo: FBInstant.AdInstance = null;

public initFBAd() {
	let self = this;
	FBInstant.getInterstitialAdAsync(
	"Placement Id" // Your Ad Placement Id
	)
	.then(function (interstitial) {
		// Load the Ad asynchronously
		self.preloadedRewardedVideo = interstitial;
		return self.preloadedRewardedVideo.loadAsync();
	})
	.catch(function (err) {
		console.error("Interstitial failed to preload: " + err.message);
	});
}

public playFBAd(){
	let videoObj = this.preloadedRewardedVideo;
	let self = this;
	if (videoObj != null) {
		videoObj
		.showAsync()
		.then(function () {
			// Perform post-ad success operation
			console.log("Rewarded video watched successfully");
			self.initFBAd();
		})
		.catch(function (e) {
			console.error(e.message);
		});
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值