Hi all
I’m trying to build a Content Container Template that will allow an editor to specify up to 10 Instagram posts to show in a styled timeline.
The Instagram API provides an endpoint to fetch specific posts with a basic request (see: https://developers.facebook.com/docs/instagram/embedding#sample-request).
Ideally, I’d like to use a REST Resource asset to dynamically call the posts as provided by the editor, looping through and returning the data for each one, but if I try to print the results of a REST Resource asset call in an SSJS loop, it only returns the first result.
For example, the following has three requests, but only returns the first post:
<script runat="server">
var rawPostURLs = "%globals_asset_metadata_instaPosts%",
postURLs = rawPostURLs.split(';');
for (i=0; i < postURLs.length; i++){
print('%' + 'globals_asset_contents_raw:3387544^with_get:postURL' + postURLs[i] + '%');
}
</script>
Whereas this returns all three:
<script runat="server">
var rawPostURLs = "%globals_asset_metadata_instaPosts%",
postURLs = rawPostURLs.split(';');
print('%' + 'globals_asset_contents_raw:3387544^with_get:postURL' + postURLs[0] + '%');
print('%' + 'globals_asset_contents_raw:3387544^with_get:postURL' + postURLs[1] + '%');
print('%' + 'globals_asset_contents_raw:3387544^with_get:postURL' + postURLs[2] + '%');
</script>
If an editor can specify up to 10, 15 or 20 posts, then the second method becomes unworkable pretty rapidly.
It might be that the best solution is to loop through the requests with an AJAX call (or some other pure JS method), but the REST Resource asset provides some useful functionality and would be our preferred method if possible.