How to: Update FriendFeed using ASP

By Last week the popular feed aggregator FriendFeed launched their new API.

FriendFeed Logo The new API makes it easy for anyone to create custom applications to interact with FriendFeed.

Below is a script I wrote in ASP to post an image and link to your feed stream using XMLHTTP. I’ve included the complete script for download at the bottom of this post.

‘*** set your FriendFeed username and remote key variables
‘*** your users can obtain their remote key here:
ff_username = “username”
ff_remotekey = “remotekey”

‘*** set the URL you want to link to
ff_url = “”

‘*** set the text to add to your post
ff_update = “Visit”

‘*** set the image URL to post to FriendFeed
‘*** this will be posted as a thumbnail on your feed
ff_filename = “”

‘*** package all of your variables in one variable to post to the FriendFeed API
ff_post = “http://” & URLEncode(ff_username) & “:” & URLEncode(ff_remotekey) & “” & URLEncode(ff_update) & “&link=” & URLEncode(ff_url) & “&image0_url=” & URLEncode(ff_filename)

‘*** post the update
Set xml = Server.CreateObject(“Microsoft.XMLHTTP”)
xml.Open “POST”, ff_post, False
xml.setRequestHeader “Content-Type”, “content=text/html; charset=iso-8859-1”
Set xml = Nothing

That’s it! Using the above method you can easily create scripts to update FriendFeed with text, links, and photos!

Download Source File to Update FriendFeed using ASP

How to: Update Pownce using ASP

By On February 28th, 2008 Pownce released version 2.0 of their API. The major update in this new version is the ability to post messages, links, files, events and even replies via the API directly to a account.

Pownce LogoBelow is an ASP script I wrote to update your Pownce profile automatically through the new API. I’ve included the complete script for download at the bottom of this post.

Pownce requires the username and password values be encoded using base64. Below is an ASP function that will convert any value over to base64 encode.

const BASE_64_MAP_INIT = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/”
dim nl
‘ zero based arrays
dim Base64EncMap(63)
dim Base64DecMap(127)

‘ must be called before using anything else
PUBLIC SUB initCodecs()
‘ init vars
nl = “

” & chr(13) & chr(10)
‘ setup base 64
dim max, idx
max = len(BASE_64_MAP_INIT)
for idx = 0 to max – 1
‘ one based string
Base64EncMap(idx) = mid(BASE_64_MAP_INIT, idx + 1, 1)
for idx = 0 to max – 1
Base64DecMap(ASC(Base64EncMap(idx))) = idx

‘ encode base 64 encoded string
PUBLIC FUNCTION base64Encode(plain)

if len(plain) = 0 then
base64Encode = “”
exit function
end if

dim ret, ndx, by3, first, second, third
by3 = (len(plain) 3) * 3
ndx = 1
do while ndx <= by3 first = asc(mid(plain, ndx+0, 1)) second = asc(mid(plain, ndx+1, 1)) third = asc(mid(plain, ndx+2, 1)) ret = ret & Base64EncMap( (first 4) AND 63 ) ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second 16) AND 15 ) ) ret = ret & Base64EncMap( ((second * 4) AND 60) + ((third 64) AND 3 ) ) ret = ret & Base64EncMap( third AND 63) ndx = ndx + 3 loop ' check for stragglers if by3 < len(plain) then first = asc(mid(plain, ndx+0, 1)) ret = ret & Base64EncMap( (first 4) AND 63 ) if (len(plain) MOD 3 ) = 2 then second = asc(mid(plain, ndx+1, 1)) ret = ret & Base64EncMap( ((first * 16) AND 48) + ((second 16) AND 15 ) ) ret = ret & Base64EncMap( ((second * 4) AND 60) ) else ret = ret & Base64EncMap( (first * 16) AND 48) ret = ret & "=" end if ret = ret & "=" end if base64Encode = ret END FUNCTION ' initialize call initCodecs

Every site/script that interacts with the Pownce API requires an application key. To get your application key, simply register a new application on Pownce. Just replace {app_key} in the below script with the application key that Pownce provides to you.

In this example we will be posting a LINK to your Pownce profile. Be sure to reference the Pownce 2.0 API documentation for specifications on posting messages, events, files, etc.

‘*** set your Pownce username and password variables
p_username = “username”
p_password = “password”

p_username = p_username & “:” & p_password

‘*** Base64 encode your username and password
p_username = base64Encode(p_username)

‘*** replace {app_key} with YOUR application key
strPownce = “{app_key}”

‘*** the link you want to post to Pownce
pownce_link = “”

‘*** the description you want to post to Pownce
pownce_update = “ Logo – Foo You!”

Set xml = Server.CreateObject(“Microsoft.XMLHTTP”)
xml.Open “POST”, strPownce, False
xml.setRequestHeader “Content-Type”, “application/x-www-form-urlencoded”
xml.setRequestHeader “Authorization”, “BASIC ” & p_username
xml.Send(“note_to=public&url=” & pownce_link & “&note_body=”&pownce_update)

‘*** view the Pownce response
Response.Write xml.responseText

Set xml = Nothing

That’s it! Using the above method you can easily create scripts to update Pownce with anything you would like.

Download Source File to Update Pownce using ASP

How To: Update your Twitter status with ASP

Here is a simple script I wrote in classic ASP to update your Twitter status via the Twitter API. This script handles basic HTTP authentication to validate your Twitter account and URL Encoding to send over friendly status updates.

Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")

twitter_username = "username"	'change to your twitter username
twitter_password = "password"	'change to your twitter password

new_status = "visit!"		'change to your new status

xml.Open "POST", "http://" & twitter_username & ":" & twitter_password & "" & server.URLencode(new_status), False
xml.setRequestHeader "Content-Type", "content=text/html; charset=iso-8859-1"

Response.Write xml.responseText		'view Twitter's response

Set xml = Nothing

How To: Create ASP and AJAX username availability check example

So you’re using Classic ASP and you want to incorporate some AJAX into your scripts? No problem! The below example shows how easily it is to include a username availability check on your site using classic ASP and AJAX.

The below example checks the username after each key is pressed rather than when the form is submitted. You will need to create two files: ajax.asp and ajax_username.asp

You can download the sample source files at the bottom of this post

ajax.asp code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

	<TITLE>ASP and AJAX username availability check</TITLE>
	<script language="javascript">
	function OnChangedUsername()
		if(document.form1.newuserid.value == "")
				document.form1.btnCheckAvailability.disabled = true;
			document.form1.btnCheckAvailability.disabled = false;
	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
			ro = new XMLHttpRequest();
		return ro;

	var http = createRequestObject();

	function sndReq() {'get', 'ajax_username.asp?username='+document.form1.newuserid.value);
		http.onreadystatechange = handleResponse;

	function handleResponse() {
		if(http.readyState == 4){
			var response = http.responseText;
			var update = new Array();

			if(response.indexOf('|' != -1)) {
				update = response.split('|');
				document.getElementById("username_chk").innerHTML = update[0];

<form method="post" action="javascript:void(0);" name="form1">
			<td><input type="newuserid" name="newuserid" id="newuserid" size="20" onKeyUp="sndReq();" /></td>
			<td><input id="btnCheckAvailability" type="button" disabled="disabled" value="Check Availability" onClick="sndReq();"></td>
			<td><div ID="username_chk"></div></td>
			<td>Brought to you by <a href="" target="_blank">Brad Williams</a></td>


ajax_username.asp code:

Set username = Request.QueryString("username")

db_username = "username"		'DB username
db_password = "password"		'DB password
db_catalog = "database_name"		'DB name
dp_datasource = ""		'DB IP

Set conn = Server.CreateObject("ADODB.Connection")
conn.CommandTimeout = 0
c="Provider=SQLOLEDB.1;User ID=" & db_username & ";password=" & db_password & ";Initial Catalog=" & db_catalog & ";Data Source=" & dp_datasource & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"
conn.Open c

SQL = "SELECT username FROM table WHERE username='" & username & "' "
Set chk_username = Server.CreateObject("ADODB.Recordset")
chk_username.Open SQL, conn, 3, 3
If chk_username.EOF = False then
	response.write "USERNAME ALREADY TAKEN"
	response.write "USERNAME IS AVAILABLE"
End if

set chk_username = nothing

set conn = nothing

Just adjust the DSN-Less connection settings and the SELECT query above and your all set!

If you would rather check a username after the submit button is pressed just change this line:

to this:

DISCLAIMER – There is no error handling, form validation, or query injection functions or routines in this script. This is a basic username checking script. Be sure to include these features if you use this code!

Feel free to do whatever you would like with this code. If this helps then you might consider sending a link back to!

click here to download both source files