Libraries
From StatusNet
Contents |
[edit] Perl
# this is what Chris Thompson recommended
# this code snippet is Public Domain if it matters
use Net::Twitter;
my $nt = Net::Twitter->new(
apiurl => 'http://identi.ca/api',
apihost => 'identi.ca',
apirealm => 'Laconica API',
user => 'username',
pass => 'password'
);
$nt->update(q[testing from Net::Twitter]);
print $nt->http_code . " ";
print $nt->http_message;
Notes:
To make it work, I had to change the "apihost=> 'identi.ca'" to "apihost => 'identi.ca:80'". The format (with port :80 added) is also the same in the Net::Twitter Perl documentation. I'm using Net::Twitter 1.14.
- Net::Laconica - Perl extension for fetching from, and sending notices/messages to Status.net instances.
[edit] PHP
- oo-microblogging, an OOP Library for the Status.net API
[edit] Squeak Smalltalk
the
- REST-client, a ready-to-use image for Twitter-compatible Status.net API
[edit] Java
(Alex Bowyer) I recently had some problems posting to status.net from Java. It turns out you cannot pass your Parameters using the HttpParam class (I got a weird response with HTTP 200 OK but non-XML content).
Here is a working solution:
// vars
String URL = "http://www.mystatusnetinstance.com/mystatusnet/api/statuses/update.xml";
String username = "myusername";
String password = "mypassword";
//set up params
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("source","MyApp"));
params.add(new BasicNameValuePair("status","Hello World!"));
// prepare post
DefaultHttpClient client = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(URL);
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
// set up authentication
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
credsProvider.setCredentials(scope, creds);
client.setCredentialsProvider(credsProvider);
// execute
HttpResponse response = client.execute(httpPost, localContext);
// analyse response
System.out.println("HTTP Response Status: " + response.getStatusLine());
InputStream is = entity.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document w3cDoc = builder.parse(is);
DOMReader dom4jreader = new DOMReader();
org.dom4j.Document dom4jDoc = dom4jreader.read(w3cDoc);
// you would walk the DOM and process it here.
// For now just print XML
String XMLResponseBody = dom4jDoc.asXML();
System.out.println("XML HTTP Response: "+XMLResponseBody);
This sample makes use of HTTP Components and DOM4J