Find Posterous SITE_ID

Tony's Wiki | misc

To use the updated friendica-posterous plugin, you need your site_id and api_token. Finding your api_token is simple enough. Go to http://posterous.com/api, expand the first request (Retrieve the current user's information), and click “view token”, and a pop-up will show you your api_token.

Finding your site_id isn't as straightforward, so this is here to help.

relevant posterous post

Single Site

If you have but one posterous blog, you can use http://tonybaldwin.me/mine/findpostid.php to get your site ID, or the bash script at the bottom of this page. The linked page will not help sort out multiple sites/blogs, however. The bash script below will.

Here is the source code to the page, so you can see what it's doing:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>tonybaldwin.me - find your posterous site id number</title>
<meta name="description" content="all about tony baldwin">
<meta name="keywords" content="find your posterous site id">
<meta name="Generator" content="tcltext">
<meta name="author" content="tony baldwin">
<link href="http://tonybaldwin.me/slim.css" rel="stylesheet" type="text/css" media="screen"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<link rel="icon" type="image/png" href="http://tonybaldwin.me/favicon.png">
</head>
 
<body> 
 
<div id="content">
<h2>Find your posterous site id number.</h2>
 
<p>Enter a your posterous username (it's the e-mail address associated with your acct), password and api_token<sup>*</sup>, click "submit" to get your site_id.</p>
<form action="findpostid.php" method="get">
<p>username: <input type="text" name=user><br />
password: <input type="password" name=pass><br />
api token: <input type="apitoke" name=apitoke></p>
<p><input type="submit"></p>
 
<p><small>* <a href="https://github.com/friendica/friendica/wiki/Posterous-Plugin" target="_blank">how to find your api_token</a></small></p>
</form>
 
<?php
 
if ((isset($_GET["pass"])) && (isset($_GET["user"])) && (isset($_GET["apitoke"]))) 
 
        {
        $pass = $_GET['pass'];
        $user = $_GET['user'];
        $apitoke = $_GET['apitoke'];
        $url = "http://posterous.com/api/2/sites/";
 
        $params = array(
                'api_token' => $apitoke,
        );
 
 
 
        if($user && $pass && $apitoke) {
 
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $pass);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
 
 
                $data = curl_exec($ch);
                $result = curl_multi_getcontent($ch);
                curl_close($ch);
 
                preg_match('/"site_id":(\d+)/', $result, $matches); 
                $siteid = $matches[0];
 
                echo "<hr /><h1>$siteid</h1>";
                echo "<p><small>your site_id is the number above</small></p>";
        }
}
?>
<hr />
<p><strong>PLEASE NOTE</strong>: This will only work for users who have only 1 posterous blog.<br />
If you have several, you will have to make an API call and retrieve the full json data and figure out which is the relevant id for your purposes.<br />
For this, see <a href="http://posterous.com/api" target="_blank">posterous API</a>.</p>
<hr />
<p><a href="http://tonybaldwin.me/mine/findpostid.php">clear form</a></p>
<p><a href="http://tonybaldwin.me">HOME</a></p>
</div>
 
<div id="foot2">
 
        <p align="center">This page &copy anthony baldwin</p>
 
        <center><a href="http://www.debian.org" target="_blank"><img src="http://tonybaldwin.me/imgs/debian-bb-tiny.png" border="0" alt="powered by debian gnu/linux"></a>
                <a href="http://fsfe.org/campaigns/ilovefs/2012/ilovefs-2012.html"><img src="http://www.tonybaldwin.me/imgs/lovefreesoft.png" style="border: 0 !important;" alt="I love Free Software!"></a></center>
</div>
</body>
</html>

released according to AGPL v. 3

Multiple Sites

If you have one or more sites, you can use this bash script to get their site_id numbers:

#!/bin/bash
 
# get posterous site ID numbers for multiple sites
 
echo -e "enter your username \n(the e-mail address associated with your posterous account): "
read user
read -p "enter your password: " pass
read -p "enter your api token: " apitoken
 
curl -u $user:$pass -d "api_token=$apitoken" http://posterous.com/api/2/sites/ | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' > pdata
 
cat pdata | grep 'site_id' > siteids
cat pdata | grep 'nickname' > sitenicks
 
paste sitenicks siteids > psidlist
 
cat psidlist
rm sitenicks
rm siteids
rm pdata

This script will give output that looks like

"nickname":"somesitename"	"site_id":9648654
"nickname":"othersitename"	"site_id":6345483
"nickname":"anothersitename"	"site_id":7834551

Where “nickname” indicates the name of a site or blog and, of course, “site_id:” indicates the site_id number.

tonybaldwin 2012.05.09.14.49

shortlink to this page: http://tonyb.us/cM

~~DISQUS~~