A Note About Security: Doing this exposes your API key. Only expose read-only keys.
To get API results in JSON format, pass the format=json parameter to have results returned in JSON format. (More information about the JSON format is available elsewhere; there is a technical reference at json.org.)
For example, here's the URL for a regular API request as described above, which will return a feed in XML format:
Here's the same request URL with the addition of a parameter indicating the results should be formatted as JSON instead of XML:
You can look at the live output of a feed in JSON format.
As a reference, you can view a live example using JSON feeds.
You can optionally also pass the callback=functionname parameter to have the JSON result data passed to that function. (More information about the JSONP technique is available elsewhere; a good starting point is available here.)
This approach allows you to define custom functions that will handle the results of each API call.
As a reference, you can view a live example using a JSONP callback.
Finally, you may choose to use the Magnify JS-API library, which provides functions for retrieving and formatting some of the most commont types of API information.
Here's an example using the JS API to retrieve and display links to pages matching a specific search term:
The key elements of the example are as follows:
magnify_api_set_channel_keyto set the channel name and API key.
magnify_api_asynchone or more times to invoke API functions and handle the information they send back.
magnify_api_asynch function is asynchronous, meaning that, where possible, it doesn't make the user wait for the API function to complete before displaying the rest of the page -- instead, it initiates a request and provides a way of handling the result when it arrives (which may be a fraction of a second or as much as a couple of seconds later, depending on network conditions).
Each time you call
magnify_api_asynch you specify:
magnify_api_set_channel_keyis automatically added to the arguments that are passed to the API server.)
., a new
<div>tag is created with a unique ID to hold the results. If you pass
0or an empty value, the function results will not be displayed anywhere.
Several feed formatting functions are included and can be passed as the third parameter to the
magnify_api_content_links: Shows the title of each content item, with a links to its player page.
magnify_api_content_link_divs: Similar to
magnify_api_content_links, but with each link wrapped in
magnify_api_content_teasers: Shows the title, thumbnail image, and description for each content item.
As a reference, you can view a live example using the JS-API library.