Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djacobs/359155 to your computer and use it in GitHub Desktop.
Save djacobs/359155 to your computer and use it in GitHub Desktop.
<html>
<body>
<h3>External Assets Example</h3>
<?php
/***** Utility methods + constants ******/
define ("DEFAULT_DEBUG_MODE", 1);
define ("ROOT_TYPEPAD_API_URL", "http://api.typepad.com");
/*************
* get_tpconnect_external_assets_api_url()
* -- returns the TP API endpoint
*************/
function get_tpconnect_external_assets_api_url($xid) {
return ROOT_TYPEPAD_API_URL . '/blogs/' . $xid . '/discover-external-post-asset.json';
}
/*************
* post_json()
* -- Posts a JSON request to the url of your choice;
* -- returns the JSON-decoded response
*************/
function post_json ($url, $params) {
if (DEFAULT_DEBUG_MODE) {
echo "<p class='request'>[POST_JSON], URL = <a href='$url'>$url</a></p>";
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json;"));
return json_decode(curl_exec($ch));
}
/*********
* Example
*********/
// This is the example blogXID + permalink given in the Rousseau (Daily News) example
$blog_xid = '6a00e5539faa3b88330120a94362b9970b';
$my_permalink = 'http://mtcs-demo.apperceptive.com/testmt/recent_news/2010/03/performance-artist-mimics-performance-artist-at-moma.php';
// Grabs the TypePad endpoint
$post_url = get_tpconnect_external_assets_api_url($blog_xid);
// Sends the POST request (in json format) to TypePad
$json = '{"permalinkUrl":"' . $my_permalink . '"}';
$events = post_json($post_url, $json);
// Receives the entry XID
$entry_xid = $events->asset->urlId;
echo "<p>entry_xid=$entry_xid for blog_xid=$blog_xid on permalink=<a href='$my_permalink'>here</a></p>";
?>
</body>
</html>
@djacobs
Copy link
Author

djacobs commented Apr 7, 2010

Forking is the new watching, I don't have anything to add here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment