Facebook“FB.Canvas.getPageInfo”,如何正确使用它

发布于 2024-12-23 05:21:48 字数 1838 浏览 3 评论 0原文

我需要帮助弄清楚如何正确使用 Facebook 的 javascript sdk 中的 FB.Canvas.getPageInfo

https://developers.facebook.com/docs/reference/javascript/FB.Canvas.getPageInfo/

我能够获取信息并记录/警报数据:

function getFbCanvasInfo() {
    FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
    console.log(fbCanvasInfoObject);
    });
}

$("a.GetScrollTest").live( "click", function() {
    getFbCanvasInfo();
    return false;
});

但是我不知道如何设置该数据,然后将其应用到其他元素或函数(即如下所示):

$("a#test-link").each(function() {
    var fbPosition = getFbCanvasInfo().scrollTop;
    $(this).append("<em>The scroll top value is " + fbPosition + "px");
}

我知道它不对,我在这里遗漏了一些东西。

顺便说一句,这些函数都在我的 async init 和 FB 根目录下,看起来像这样:

<div id="fb-root"></div>
<script type="text/javascript">//<!--
    window.fbAsyncInit = function()
        {
        FB.init({
            appId: '223615011031939',
            status: true, 
            cookie: true, 
            xfbml: true, 
            oauth:true, 
            channelUrl: '[MY PROJECTS CHANNEL URL]' 
        });
        var isLoaded = true;FB.Canvas.setSize();FB.Canvas.setAutoGrow(500);            
        };

        (function() {
            var e = document.createElement('script');
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }());

        ;(function($){
            $(document).ready(function($){
                [THE JQUERY FROM ABOVE HERE]
            });
        })(jQuery);
    //--></script>

非常感谢任何有建议/专业知识的人!谢谢!

I need help figuring out how to appropriately use the FB.Canvas.getPageInfo from Facebook's javascript sdk:

https://developers.facebook.com/docs/reference/javascript/FB.Canvas.getPageInfo/

I'm able to get the info and log/alert the data:

function getFbCanvasInfo() {
    FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
    console.log(fbCanvasInfoObject);
    });
}

$("a.GetScrollTest").live( "click", function() {
    getFbCanvasInfo();
    return false;
});

But I can't figure out how to set that data and then apply it to other elements or functions (i.e. like something below):

$("a#test-link").each(function() {
    var fbPosition = getFbCanvasInfo().scrollTop;
    $(this).append("<em>The scroll top value is " + fbPosition + "px");
}

I know its not right and I'm missing something here.

BTW these functions are all below my async init and FB root, which appears like so:

<div id="fb-root"></div>
<script type="text/javascript">//<!--
    window.fbAsyncInit = function()
        {
        FB.init({
            appId: '223615011031939',
            status: true, 
            cookie: true, 
            xfbml: true, 
            oauth:true, 
            channelUrl: '[MY PROJECTS CHANNEL URL]' 
        });
        var isLoaded = true;FB.Canvas.setSize();FB.Canvas.setAutoGrow(500);            
        };

        (function() {
            var e = document.createElement('script');
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        }());

        ;(function($){
            $(document).ready(function($){
                [THE JQUERY FROM ABOVE HERE]
            });
        })(jQuery);
    //--></script>

Much appreciation to anyone who has advice/expertise! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫瑟鸿黎 2024-12-30 05:21:48

getPageInfo 返回一个只读对象。要“设置”事物,您需要使用文档中列出的提供的设置器函数。设置画布大小的其中之一是 setSize 请参阅 https://developers.facebook.com/docs/reference/javascript/FB.Canvas.setSize/

此外,您还应该清理您的 javascript,以便使用其 API 的异步性质是好的。

$("a.GetScrollTest").live( "click", function() {
    FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
        var fbPosition = fbCanvasInfoObject.scrollTop;
        $(this).append("<em>The scroll top value is " + fbPosition + "px");
    });
    return false;
});

The getPageInfo returns a readonly object. To "set" things, you would need to use the provided setter functions listed in the documentation. One of them to set the size of the canvas is setSize see https://developers.facebook.com/docs/reference/javascript/FB.Canvas.setSize/

Also you should cleanup your javascript so the async nature of working with their API is good.

$("a.GetScrollTest").live( "click", function() {
    FB.Canvas.getPageInfo(function(fbCanvasInfoObject) {
        var fbPosition = fbCanvasInfoObject.scrollTop;
        $(this).append("<em>The scroll top value is " + fbPosition + "px");
    });
    return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文