Facebook:“#2635您正在调用不推荐使用的Ads API版本请更新到最新版本:v7.0”

问题描述

尝试拨打电话时:

        FB.api(`/${authResponse.userID}/adaccounts`,accountsResponse => {
            console.log('accountsResponse ',accountsResponse);
        });

根据文档here,我们收到以下答复:

error:
code: 2635
fbtrace_id: "AtKWTpvIoYCi5YXpg-2Xr0g"
message: "(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v7.0."
type: "OAuthException"

麻烦的是,我们正在使用v8.0版本,这与错误消息中包含的信息相反,是最新版本!

这是我们使用Nuxt加载SDK的方式:

        {
            // replaced "sdk.js" with "all.js" due to "init not called with valid version"
            // problem solved... but apparently this is bad
            // see https://gist.github.com/tpai/602898fe0d3d630f0099d58856cef352
            // other proposed solutions fail.
            src: 'https://connect.facebook.net/en_US/all.js',crossorigin: 'anonymous',async: true,defer: true,}

所以这有点奇怪,但是我们根本无法使建议的“ sdk.js”正常工作,至少可以加载并允许我们成功调用FB.login()。

这是我们初始化的方式:

                        FB.init({
                            appId,autoLogAppEvents: true,xfbml: true,version: 'v8.0',});

将此版本号更改为“ v7.0”无效。

解决方法

因此,似乎在head()中加载sdk.js而不是使用标签会以某种方式使所有人困惑。由于令Vue感到不满,我们不得不找到另一个解决方法,right here

mounted() {
        const fbDiv = document.createElement('div');
        fbDiv.id = 'fb-root';
        document.body.appendChild(fbDiv);
        // run after sdk is loaded
        window.fbAsyncInit = () => {
            FB.init({
                appId,autoLogAppEvents: true,xfbml: true,version: 'v8.0',});
        };
        // inject sdk.js
        (function (d,script) {
            script = d.createElement('script');
            script.type = 'text/javascript';
            script.async = true;
            script.src = `https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v8.0&appId=${fbAppId}&autoLogAppEvents=1`;
            d.getElementsByTagName('head')[0].appendChild(script);
        })(document);
    }