Facebook即时文章HTML POST错误

时间:2019-01-18 20:51:27

标签: facebook http facebook-graph-api post facebook-instant-articles

我通过将HTML内容发布到https://graph.facebook.com api中遇到了一个障碍。我能够成功发布到端点,并且收到状态ID作为响应。然后,当我在端点上使用GET检查状态时,错误消息告诉我我的内容格式不正确。我能够在即时文章中的频道上手动发布完全相同的HTML内容,并且不会收到有关HTML格式的警告。我也尝试过使用Facebook提供的示例文章HTML,它也会返回错误消息。任何建议表示赞赏。这是我的要求的示例:

POST /{my_page_id}/instant_articles?access_token={my_access_token}&amp; html_source=<!DOCTYPE html><html lang="en" prefix="op: http://media.facebook.com/op HTTP/1.1
Host: graph.facebook.com
cache-control: no-cache
Postman-Token: {postman_token}
<!---Facebook Sample Article Content--->
<!doctype html>
        <html lang="en" prefix="op: http://media.facebook.com/op#">
        <head>
                <meta charset="utf-8">
                <!--Canonical URL of the article from site -->
                <link rel="canonical" href="{my_Facebook_approved_domain/canonical_url}">
                <link rel="stylesheet" title="{my_stylesheet}" href="#">
                <!--Article Title-->
                <title>{my_article_title}</title>
                <meta property="fb:article_style" content="{my_stylesheet}">
        </head>
        <body>
                <article>
                        <header>
                                <!-- The header image shown inside your article -->
                                <figure>
                                        <!-- First Figure from the article -->
                                        <img src="{my_image_url}">
                                </figure>
                                <!-- Article Title -->
                                <h1>{my_article_title}</h1>
                                <!--Article Teaser-->
                                <h2>{my_article_subtitle}</h2>
                                <!-- The authors of the article -->
                                <address>{list_of_authors}</address>
                                <!--The published and last modified time stamps-->
                                <time class="op-published" dateTime="2019-01-10T16:00">January 10 2019, 04:00 PM</time>
                        </header>
                           <p>{my_content}</p>
                           <p><a href="{my_canonical_url}"> Read the Full Story at {my_site}</a></p><br>
                        <footer>
                           <!-- Copyright details for your article -->
                           <small>© 2019 {my_site}.  All Rights Reserved.</small>
                        </footer>
                </article>
        </body>
</html>

提交POST请求后,我得到如下响应:

{
    "id": "2005563182874064"
}

然后我通过调用以下方法获取文章状态端点:

GET /{page_id}?access_token={my_access_token}&amp; fields=errors,html_source,instant_article,status HTTP/1.1
Host: graph.facebook.com
cache-control: no-cache
Postman-Token: {postman_token}

...我从该端点得到的响应如下:

{
    "errors": [
        {
            "level": "ERROR",
            "message": "AttValue: \" expected"
        },
        {
            "level": "ERROR",
            "message": "Couldn't find end of Start Tag html"
        },
        {
            "level": "ERROR",
            "message": "Missing Article's Canonical URL: There is no URL specified for this article. A canonical URL needs to be claimed and placed within the HTML to generate an Instant Article. Refer to URLs under Publishing Articles in the Instant Articles documentation for more information on claiming and inserting a canonical URL."
        }
    ],
    "html_source": "<!DOCTYPE html><html lang=\"en\" prefix=\"op: http://media.facebook.com/op",
    "status": "FAILED",
    "id": "2005563182874064"
}

我的HTML中肯定存在规范的URL,并且对它进行了三倍检查,以确保它在我的Facebook页面的“配置/工具/连接您的站点”区域中列出。同样,我能够手动上载相同的HTML并使用移动设备上的Pages App进行预览。只有在我尝试通过API推送内容时才会失败。

我正在用POSTMAN测试我的所有调用,然后将这段代码转换为Python3。再次感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您始终希望将有效负载数据放置在POST请求的主体中,并作为GET的查询字符串。每当API调用看起来像URL极端的数据(不能超过2083个字符)时,这就是一个关键指标,表明这可能不是GET。