ImpSdk.getSocialPosts

Developed by Meysam Ghaderyan and Saurabh Chauhan. Demo page created by Timmy Luong.

ImpSdk.getSocialPosts(options, callback)

Attempts to get the most recent social media posts from our internal endpoint based on options. Must pass arguments to both parameters including the callback function to handle the error or data received.

Parameter Type Description
options Object 1st parameter. A parent Object containing all of the separate options for each of the individiual social media platforms. Each child Object contains properties and values used by our endpoint to query a specific social media platform and filtering the results.

// For example:
var options = { 'twitter': {...}, 'instagram': {...} };

Each child Object {...} has the following properties and values:
Property Value
campaign: Optional. A string containing keywords for campaigns to be filtered.
query: Required. A string used by our endpoint to query the social media platform for posts.
accounts: Optional. An array of strings to identify the only accounts from which to get posts.
count: Optional. An integer representing the number of posts to get.
result_type: Optional. A string identifying the type of posts to get. Defaults to 'mixed' when not specified. Possible choices are: 'mixed', 'popular', 'recent'.
mediaOnly: Optional. A boolean filter to get only posts that include media (pictures, etc.). This property is ignored when passed to Instagram (which always has media).
next_id: Optional. A string id for the next set of results. This property enables us to use pagination when receiving large data sets. For a demonstration of pagination, use the demo page button at the top of this page.
Parameter Type Description
callback Function 2nd parameter. A Node.js-style callback function, executed on the error or data returned by our endpoint. Typically this function is an anonymous function defined within the call to ImpSdk.getSocialPosts( ) but can also be a pre-defined function. This function usually has an if-else block handling the error or data.

The callback will be executed with two arguments:
callback(error, data);
Argument Description
error Required. When error exists, it is a string holding the error message describing why no data was returned, and the other argument data will be passed undefined.
data Required. When data exists, it is an Object containing the posts, pagination ids, and platform-specific error messages, and the other argument error will be passed undefined.

See the JSON example below for in-depth details on the data. The Demo Page also includes a high-level view of the data object.

Example code:

var options = {
  twitter: { // optional
    campaign: 'fireworks', // optional
    query: 'preparations OR Tough', //mandatory. for twitter you can pass a twitter-compatible query (https://dev.twitter.com/rest/public/search).
    accounts: ['@NFL', '@MoveTheSticks'], // optional. Gets posts from either of the accounts
    count: 3, // optional. number of posts to get.
    result_type: 'mixed', //optional. possible values are 'mixed', 'popular' and 'recent'. default is 'mixed'.
    mediaOnly: false, //optional. default is false
    next_id: '', // optional in first call , get value from the 'twitterNextId' field and populate in the next call.
  },
  instagram: { // optional
    campaign: 'fireworks',
    query: 'Macys',
    accounts: [],  // for example ['macys', 'bloomingdales'],
    count: 3,
    result_type: 'mixed',
    next_id: '', // optional in first call , get value from the 'twitterNextId' field and populate in the next call.
  }
}
ImpSdk.getSocialPosts(options, function(err, data) {
  if (err) {
    // handle err properly
  } else {
    console.log(data);
  }
});

Click 'Show JSON' to see an example data object. And for an in-depth demo, see the top of the page.