Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
External Post Asset Example (PHP)
<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>
@nataliepo

This comment has been minimized.

Copy link
Owner Author

nataliepo commented Apr 2, 2010

It looks like I can only submit a permalink with the same domain as my TPConnect'd blog. Settings have the URL configured to be:
http://mtcs-demo.apperceptive.com/testmt/recent_news

These requests fail:
$my_permalink = 'http://www.nataliepo.com';
$my_permalink = 'http://mtcs-demo.apperceptive.com/testmt/';

These succeed:
$my_permalink = 'http://mtcs-demo.apperceptive.com/testmt/recent_news/2010/03/nonexistent.php';
$my_permalink = 'http://mtcs-demo.apperceptive.com/testmt/recent_news/';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.