I've hit a blocker with POST'ing of HTML content to the https://graph.facebook.com api. I'm able to successfully POST to the endpoint and I receive a status ID as a response. When I then use a GET on the endpoint to check the status, the error messages tell me my content is malformed. I'm able to manually publish the exact same HTML content on my channel in Instant Articles and I get no warnings about the formatting of the HTML. I've also tried using the sample article HTML provided by Facebook and that returns error messages as well. Any advice is appreciated. Here are samples of my requests:
POST /{my_page_id}/instant_articles?access_token={my_access_token}& 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>
After submitting the POST request, I get a response that looks like this:
{
"id": "2005563182874064"
}
I then GET the article status endpoint by calling:
GET /{page_id}?access_token={my_access_token}& fields=errors,html_source,instant_article,status HTTP/1.1
Host: graph.facebook.com
cache-control: no-cache
Postman-Token: {postman_token}
...and the response I get from that endpoint is as follows:
{
"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"
}
The canonical URL is certainly present in my HTML and I've tripled checked that it's listed in the Configuration/Tools/Connect your site area of my Facebook page. Again, I'm able to manually upload the same HTML and preview it using the Pages App on a mobile device. It's only failing when I try to push the content via the API.
I'm testing all of my calls with POSTMAN and will then convert this code to Python3. Again, thanks for your help.
You always want to place payload data in the body of the request for POSTs and as a query string for GET. Anytime an API calls for data that looks extreme for a URL (can't be longer than 2083 characters), that's a key indicator that this is probably not a GET.