|
Using Feeds
Video Tutorial
Getting Content Updates Using Next Page Links (02:31)
About Feed Workflows
Most Feed workflows fall into one of these two main categories:
Getting
Content Updates Using Next Page Links
Important |
|
If you are requesting
feeds and want to receive all content related to your query as
that content becomes available, you must
follow the "next_page"
link from the feed response, as shown in the example below. This
will ensure that the next feed request picks up precisely where
the last request left off and that you do not miss any content
or receive excessive duplicate files. |
|
|
|
Example: next_page link
{
"api_version": "2.0",
"api_mode": "live",
"api_build": "2.0.2",
"id": "sym86viZrF",
"method": "/content/feed.GET",
"org_name": "My Organization",
"params": {
"page_size": 50,
"q": "prodictid:30598",
},
"data": {
"query": "prodictid:30598",
"updated": "2019-06-25T19:30:35.421Z",
"page_size": 10,
"current_item_count": 50,
"next_page": "https://api.ap.org/media/v/content/feed?qt=sym86viZrF&seq=64292965",
"items": [
...
Tip |
|
To receive your AP breaking
news content in a timely manner and to ensure your feeds do not
get behind, follow the "next_page"
link as soon as it is returned in the feed. Because of the long
polling feature, there is no need to wait any period of time
between your polling requests. |
|
|
|
If there have been changes since your previous request, the server sends
back the HTTP/200 OK header and the new content items in the response
body. If there have been no changes, the server returns the HTTP/200 OK
header and only the link for the next request in the response body.
A query token (the qt parameter
value in the "next_page"
link) expires after 72 hours of inactivity. If you follow the "next_page" link after the token
has expired and receive an error message 400, 6060, resubmit
your original request.
Getting
the Latest Content Using Conditional Requests
Important |
|
If you are periodically
requesting the latest content relating to your query; for example,
to refresh the top ten stories on your front page or ticker, your
client application must send a conditional GET request to the
AP Media API server to check if there have been any updates since
your last request. This practice is used almost universally by
standard web sites and web browsers. It helps avoid redundant
processing of unchanged responses and greatly improves the efficiency
of client applications. |
|
|
|
AP Media API responses include the ETag header; for example:
HTTP/1.x 200 OK
...
Etag: "4135cda4" (a unique hash for
the document)
When making a conditional request, your client application must provide
the AP Media API server the ETag identifier of the previous request using
the If-None-Match header. If the clients document
is the latest (based on this value), the server send back the HTTP/304
Not Modified header without the response body. Alternatively, if the client's
document is outdated, the server sends back the HTTP/200 OK header and
the new response body.
Tip |
|
To receive your AP breaking
news content in a timely manner, submit a new request with the
ETag identifier of the previous request as soon as the Etag is
returned by the Media API server. Because of the long polling
feature, there is no need to wait any period of time between your
polling requests. |
|
|
|
Example: Getting the latest items
To get the latest 20 items for some products:
Compose the request (make
sure to supply the API key in the x-api-key
request header):
.../content/feed?q=productid:(32498+OR+41664)&page_size=20
If you receive a HTTP/200
OK response, do both of the following:
Save the returned
ETag header to issue along with your next request.
Process the response
as you would normally do; for example, rebuild your web page or
refresh Word Press.
When you want to refresh
your web page, submit your previous URL again and set the HTTP Request
Header If-None-Match to the value of the
ETag header from the previous response.
The Media API uses that
header value to determine if the content you have previously received
is still up-to-date. If it is not, the API will respond with a new
ETag header and the fresh items. You will receive the 20 latest items,
at least one of which will be new or updated.
|
|