美文网首页app开发
Facebook小游戏对接总结

Facebook小游戏对接总结

作者: DanDing | 来源:发表于2019-09-30 17:37 被阅读0次

    懵新对接时facebook小游戏文档按要求跑流程。账号每次都是在一两天被莫名其妙的上传照片,验证收不到等问题。所有问题都是: vpn的IP不固定,或者不稳定造成的!前期一定要把账号稳定。住!!!
    一.代码逻辑:
    1.初始化(后面所有接口都在完成后操作)

    FBInstant.initializeAsync().then(function () {});
    

    2.平台区分

    FBInstant.getPlatform() /**WEB/IOS/ANDROID/MOBILE_WEB*/
    

    3.进度

    FBInstant.setLoadingProgress(progress);
    

    4.用户信息

    FBInstant.startGameAsync().then(function () {
                this.contextId = FBInstant.context.getID();
                this.contextType = FBInstant.context.getType();
                this.playerName = FBInstant.player.getName();
                this.playerPic = FBInstant.player.getPhoto();
                this.playerId = FBInstant.player.getID();
            });
    

    5.分享

        FBInstant.shareAsync({
            intent: 'REQUEST',
            image: base64,
            text: "Come and play together",
            data: shareData.data,/**分享额外数据*/
        }).then(function () {
        });
    

    6.base64处理

    Base64: function (src, callback) {
            let img = new Image();
            img.crossOrigin = 'Anonymous';
            img.onload = function () {
                let canvas = document.createElement('CANVAS');
                canvas.height = 533;
                canvas.width = 960;
                canvas.getContext('2d').drawImage(this, 0, 0, 960, 533);
                return callback(canvas.toDataURL());
            };
            img.src = src;
        }
    

    7.广告(插屏,视频基本逻辑差不多) --->下面以插屏广告为例子

    /**AdPreloadArray 存放广告Id数组 AdIdArray存放预加载实例化*/
    for (var i = 0; i < AdPreloadArray.length; i++) {
          this.interstitialAd(AdPreloadArray[i], i);
        }
        interstitialAd: function (adId, i) {
            FBInstant.getInterstitialAdAsync(adId).then(function (interstitial) {
                AdIdArray.push(interstitial);
            }).then(function () {
            }).catch(function (error) {
            });
    

    预加载

    preload: function (posId, callback) {
            console.log("posId===", posId, AdIdArray);
            if (AdIdArray.length != 0)
                AdIdArray[posId].loadAsync().then(function () {
                    return callback(true, "Interstitial ready");
                }).catch(function (error) {
                    return callback(false, error.message);
                });
        },
    

    显示

    ShowAd: function (posId, callback) {
        if (AdIdArray.length != 0)
            AdIdArray[posId].showAsync().then(function () {
                  return callback(true, "Interstitial watched!");
                }).catch(function (error) {
                   return callback(false, error.message);
                });
        }
    

    8.上报信息

    FBInstant.logEvent(eventName, value, parameters);
    

    9.好友一起耍

    var player = FBInstant.player.getName();
        FBInstant.context.chooseAsync().then(function () {
        FBInstant.updateAsync({
                 action: "CUSTOM",
                 cta: "Join Now",
                 template: "play_with_friends",
                 text: { default: player + "invited you to play Fantasy Clash" },
                 image:base64,})
                })
    

    相关文章

      网友评论

        本文标题:Facebook小游戏对接总结

        本文链接:https://www.haomeiwen.com/subject/wchhpctx.html