从应用程序内喜欢Facebook粉丝页面,重新加载标签页

Liking Facebook fan page from within the app, reload the tab

本文关键字:新加载 标签 加载 应用程序 喜欢 Facebook      更新时间:2023-09-26

我想强调的第一个问题是,由于同源策略,Facebook限制和Facebook JS SDK中缺乏变量,不可能告诉加载当前应用程序的页面的URL是什么。解决方案是使用后端生成URL。但是,应该有一个JS SDK变量保存这些信息。

http://www.facebook.com/pages/[any-random-string]/[page-id-got-from-signed-request]?sk=app_[app-id]

现在来看错误本身。我使用这个URL来生成like按钮:

<div class="fb-like" data-href="<?=FACEBOOK_TAB_URL?>" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false" data-font="lucida grande"></div>

FB.Event.subscribe用于检测用户是否喜欢该内容。但是,当用户点击like按钮时,来自Facebook的响应如下:

{
    "__ar":1,
    "payload":{
        "requires_login":false,
        "success":false,
        "already_connected":false,
        "is_admin":false,
        "show_error":true,
        "error_info":{
            "brief":"An error has occurred.",
            "full":"There was an error liking the page. If you are the page owner, please try running your page through the linter on the Facebook devsite (https:'/'/developers.facebook.com'/tools'/lint'/) and fixing any errors.",
            "errorUri":"'/connect'/connect_to_node_error.php?title=An+error+has+occurred.&body=There+was+an+error+liking+the+page.+If+you+are+the+page+owner'u00252C+please+try+running+your+page+through+the+linter+on+the+Facebook+devsite+'u002528https'u00253A'u00252F'u00252Fdevelopers.facebook.com'u00252Ftools'u00252Flint'u00252F'u002529+and+fixing+any+errors.&hash=AQBOXfQcBTjYQ9b7"
        }
    },
    "jscc":""
}

显然,由于这是Facebook粉丝页面的URL, Facebook调试器对我来说没有多大用处。

此问题与Facebook缓存url有关。它出现时,你喜欢的内容,然后不喜欢,并试图在短时间内再次喜欢它。简单的解决方案是在data-href=""的末尾添加随机散列,例如使用uniqid()。

注意OpenGraph标签scraper将跟随最后一个og:url。因此,即使您将随机散列附加到date-href参数,只要被喜欢的URL有自己的og:url标记,计数器将正常工作。

相关文章: