Wednesday, April 15, 2009

Google Friend Connect - Capture ID

Find out your members' unique ids (sometimes referred to as userid or user id) in Google Friend Connect. Useful for integrating friend connect into your existing web forms, applications or tracking.

Ever have one of those days where that you think something is going to be really easy and 5 hours later you're ready to pull your hair out?

That's how I felt about Google friend Connect. Don't get me wrong it's extremely easy if you are only playing with the provided gadgets but the developer's section can make you squirm.

Google does a good job of explaining the initial pieces of code you need in your page in order to connect to the API:

What Google doesn't give you is a quick example on capturing only the unique userid. Here's the code to make that happen.

Step 1: Paste this in the header section of your webpage

<script src="" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">
google.load('friendconnect', '0.8');

<script type="text/javascript">
site: 'XXXXXXXXXXXXXXX', // Change this on your site
onload: function() { initAllData(); }

function initAllData() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest("VIEWER"), "viewer");

// load the data using open social
function loadData() {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), 'viewer');

// called after data is loaded
function onLoadCallback(data) {
if(data.get('viewer').getData()) {
var viewer = data.get('viewer').getData();
var name = viewer.getDisplayName();

//The holy grail of code that took me forever to figure out
var userid = viewer.getField( opensocial.Person.Field.ID );

// This code that will update your form field with the userid value. Be sure to change the formname value and the fieldname value to match your form.
document.FORMNAME.FIELDNAME.value = userid;

Step 2: Create your form

<form id="FORMNAME" name="FORMNAME" action="" method="post">
<input size="32" name="FIELDNAME">
<input type="submit" value="Submit">

Reference Links

Google Friend Connect Website

Google Friend Connect API Documentation (Javascript):

Supported Open Social Parameters:

Tuesday, September 16, 2008

Outlook Meeting Tracking Export

Recently I was planning an event using my Outlook calendar at work. I needed to share the list of users who had accepted the outlook invitation with my fellow event planners. Unfortunately I couldn't find a way to do this in outlook without taking screen shots of the list

I found a website where someone had written a macro to export the list in word.

The code didn't work in Office 2007 so I tweaked it and decided to take it one step further. I set it to export my list to Excel, instead of word, where I could quickly sort by name or acceptance.

If you have never created a macro before this may be a little intimidating but here's some easy instructions I got from Google Groups

  1. Copy the code below

  2. Open Outlook

  3. Press your <ALT>+<F11> (This opens the Microsoft Visual Basic - VbaProject.OTM)

  4. On the menu across the top select "Insert"

  5. Select "Module"

  6. In the blank window on the right, PASTE the code you copied

  7. Select "File"

  8. Select "Close and Return to Microsoft Outlook"

  9. Right click on your Tool menu (in the gray part where the buttons are)

  10. Select "Customize..."

  11. Click on the "Commands" tab

  12. Select "Macros" from the Categories

  13. Click on "Project1.PrintAapptAttendee" and drag it to your toolbar

    and Drop it (You have to drop it ON the toolbar not in the gray

    blank area but next to something like the yellow question mark icon)

  14. Close the Customize window.

Now try to use this "Macro"

  1. Open an appointment that has attendees in it

  2. Click on the "Project1.PrintAapptAttendee" button that you put on your toolbar.

  3. Wait a moment for Word to open and show you your appointment with all of the attendees and how they responded to the invitation


Sub PrintAapptAttendee()

' Gather data from an opened appointment and print to
' Excel. This provides a way to print the attendee list with their
' response, which Outlook will not do on its own.

' Set up Outlook

Dim objApp As Outlook.Application
Dim objItem As Object
Dim objSelection As Selection
Dim objAttendees As Outlook.Recipients
Dim objAttendeeReq As String
Dim objAttendeeOpt As String
Dim objOrganizer As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strSubject As String
Dim strLocation As String
Dim strNotes As String
Dim strMeetStatus As String
Dim strUnderline As String ' Horizontal divider line

' Set up Excel

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

'Create the header and set the background color as yellow

objExcel.Cells(1, 1).Value = "Attendee"
objExcel.Cells(1, 1).Interior.ColorIndex = 6
objExcel.Cells(1, 2).Value = "Response"
objExcel.Cells(1, 2).Interior.ColorIndex = 6

objExcel.Cells(1, 3).Value = "Req/Opt"
objExcel.Cells(1, 3).Interior.ColorIndex = 6

On Error Resume Next

Set objApp = CreateObject("Outlook.Application")
Set objItem = objApp.ActiveInspector.CurrentItem
Set objSelection = objApp.ActiveExplorer.Selection
Set objAttendees = objItem.Recipients
Set objExcel = GetObject(, "Excel.Application")

If objExcel Is Nothing Then
Set objExcel = CreateObject("Excel.Application")
End If

strUnderline = String(60, "_") ' use 60 underline characters

On Error GoTo EndClean:

' check for user problems with none or too many items open
Select Case objSelection.Count

Case 0
MsgBox "No appointment was opened. Please opten the appointment to print."
GoTo EndClean:

Case Is > 1
MsgBox "Too many items were selected. Just select one!!!"
GoTo EndClean:
End Select

' Is it an appointment

If objItem.Class <> 26 Then
MsgBox "You First Need To open The Appointment to Print."
GoTo EndClean:
End If

' Get the data

dtStart = objItem.Start
dtEnd = objItem.End
strSubject = objItem.Subject
strLocation = objItem.Location
strNotes = objItem.Body
objOrganizer = objItem.Organizer
objAttendeeReq = ""
objAttendeeOpt = ""

' Get The Attendee List

For x = 1 To objAttendees.Count

strMeetStatus = ""

Select Case objAttendees(x).MeetingResponseStatus

Case 0
strMeetStatus = "No Response"

Case 1
strMeetStatus = "Organizer"

Case 2
strMeetStatus = "Tentative"

Case 3
strMeetStatus = "Accepted"

Case 4
strMeetStatus = "Declined"

End Select

If objAttendees(x).Type = olRequired Then

objExcel.Cells(x + 1, 1).Value = objAttendees(x).Name
objExcel.Cells(x + 1, 2).Value = strMeetStatus
objExcel.Cells(x + 1, 3).Value = "Required"


objExcel.Cells(x + 1, 1).Value = objAttendees(x).Name
objExcel.Cells(x + 1, 2).Value = strMeetStatus
objExcel.Cells(x + 1, 3).Value = "Optional"

End If
RowCount = RowCount + 1

'Sort Worksheet

objExcel.Worksheets("Sheet1").Range("B2").Sort _
Key1:=objExcel.Worksheets("Sheet1").Columns("B"), _

objExcel.Worksheets("Sheet1").Range("A2").Sort _
Key1:=objExcel.Worksheets("Sheet1").Columns("B"), _

objExcel.Worksheets("Sheet1").Range("C2").Sort _
Key1:=objExcel.Worksheets("Sheet1").Columns("B"), _


Set objApp = Nothing
Set objItem = Nothing
Set objSelection = Nothing
Set objAttendees = Nothing
Set objExcel = Nothing
Set objxls = Nothing
Set excelRng = Nothing
Set wordPara = Nothing

End Sub

---->UPDATE (9/19/08): Please note you are using this macro at your own risk.

Many people were complaining that they could only run the item once and then it stopped working. I did some research and it turn outs that Outlook disables all "untrusted" Macros.

To get this to run more than once you will need to go to:

Tools > Trust Center and Macro Security > and change the radio button to "Warning for all macros"

You will need to close outlook completely (make sure it's not running as a background task) then reopen it.

You will receive a warning each time you run this macro but it should still work.

Monday, July 28, 2008

Google Calendar Event Images

Many college are jumping on Google Apps to begin hosting student email. One of the features of Google Apps is the public calendar where you can post college events.

There are some limitations with Google Calendar:

  1. When you create an event you cannot add custom fields. There's no field for a brief description (teaser) or image.
  2. When I asked Google how to add additional fields they recommended using the API and writing a custom application that uses the google calendar database as a backend. Unfortunately I don't have the time or the resources to do that right now.

I wanted to be able to embed google calendar items in a webpage with a one line teaser and picture.



How did I do it?

To get around this I added the subject and the image to the description but google likes to strip out the html tags. I created a new event on my calendar and in the description box I typed:

This is my description of the event. It can be as long as I need. This is where I would type all the details that would show up after someone clicks the link.
Subject: This is my teaser

I parsed the xml file created by google and extracted the image and subject from the description. I wrapped the image and subject in the proper html tags when I displayed the content on my webpage.

Here is what the Google Calendar XML file looks like:

I found a free ASP script to display RSS/XML feeds - ByteScout (Big thanks to ByteScout for sharing your code with the world)

zip Download my modified version

I used regular expressions to extract the subject and image. Please note I'm awful at Regular Expressions but I found this great site where people share their completed expresssions:

To install this code you'll need to change the URLToRSS =
to your Google Calendar XML Address.

How do I find my Google Calendar XML Address?

It's a little tricky to find your XML Address

Step 1: Open your Google Calendar:

Step 2: Click on "Settings" in the upper right hand corner.

Step 1

Step 3: Under the "Calendars" tab select your calendar.

Step 2

Step 4: Under "Sharing" click on "Sharing:Edit Settings"

step 3

Step 5: Under the "Share the Calendar" tab you need to make the Calendar Public in order for your feeds to show events.

Step 3

Step 6: Under the "Calendar Details" tab there are links to your XML, ICAL and HTML calendars.

step 4

step 5

Step 7: Click on the XML link and copy the address.

step 6

Sunday, July 27, 2008

Organize Files VBS

Organize Files by Extension VB Script

I have hundreds of gigs worth of files and difficulty finding anything. Before Windows Vista I found that searching for a file could take a half hour and I realized I needed a better way to get organized. I wrote this quick Vistual Basic Script to help organize my files into subfolders by extension and date modifed.

Below is a screenshot of my folders after my files have been copied to their destination.

How it works:
1) It looks at my source folder

2) Copies the file into a new destination (I didn't do move in case something wen wrong)

3) Places the files into a subfolder by its extension and daet modified (Example - test.doc) would go into a doc_2008 folder.

4) Create a log of each file moved (in case it crashes mid-stream I know the last file moved)

License: Open Source (GNU General Public License)


Dim varstartpath, vardestination

'IMPORTANT - You need to provide a source and destination path.
varsource = "S:\Users\"
vardestination = "R:\Backup"


WScript.Echo "Done!"

'-------function to Find File Extensions------------

Function GetExtension(varfile)

'------Split the file by periods--------------------
arrayperiods = Split(varfile,".")
'------Select the characters after the last period--
varnumperiods = UBound(arrayperiods)
'------Return the value to GetExtension
GetExtension = arrayperiods(varnumperiods)

End Function

'-------Sub Procedure to Create Folders Based on File Extensions and Date------------

Sub CreateFolder(varfile,vardate)

Set objFSO = CreateObject("Scripting.FileSystemObject")

'------Find out file extension-----------------------
varextension = GetExtension(varfile)

'------Create a destination folder based on the extension and the year modified
varfolder = vardestination & "\" & varextension & "_" & year(vardate)

'------If the folder doesn't already exist then create it
If Not objFSO.FolderExists(varfolder) Then Set objFolder = objFSO.CreateFolder(varfolder)

Set objFSO=Nothing

End Sub

'-------Sub Procedure to Copy Files to a Folder------------

Sub CopyToFolder(varpath,varfile,vardate)

varextension = GetExtension(varfile)
varfilesourcepath = varpath
varfiledespath = vardestination & "\" & varextension & "_" & year(vardate) & "\" & varfile

Set objFSO = CreateObject("Scripting.FileSystemObject")

'-----Keep a log of files moved so you know where it crashed------------------

'Create or append a text file

varlog = varpath

Set fso = CreateObject("Scripting.FileSystemObject")
fpath= vardestination & "\FilesMoved.txt"

If flg Then
Set floc= fso.OpenTextFile(fpath, 8)
Set floc = fso.CreateTextFile(fpath,true)
End If

Set fso = Nothing


'------Check to see if File Exists-------------------
If Not objFSO.FileExists(varfiledespath) Then

objFSO.copyFile varfilesourcepath,varfiledespath


set objFileName = objFSO.GetFile(varfilesourcepath)
varsourcesize = objFileName.Size
varsourcemod = objFileName.DateLastModified
Set objFileName = Nothing

set objFileName = objFSO.GetFile(varfiledespath)
vardestsize = objFileName.Size
vardestmod = objFileName.DateLastModified
Set objFileName = Nothing

'------If the file was last modified at the same time and is the same size----

If (varsourcesize = vardestsize) and (varsourcemod = vardestmod) Then

objFSO.copyFile varfilesourcepath,varfiledespath,true


'------If not true then rename the file-------
varyear = year(varsourcemod)
varsourcemod = FormatDateTime(varsourcemod,2)
varsourcemod = Replace(varsourcemod, "/", "_")
arrayperiods = Split(varfile,".")
varitemname = arrayperiods(0)

varfiledespath = vardestination & "\" & varextension & "_" & varyear & "\" & varitemname & "_" & varsourcesize & "_" & varsourcemod & "." & varextension

objFSO.CopyFile varfilesourcepath,varfiledespath,true

End If

End if

Set objFSO=Nothing

End Sub

'-------Sub Procedure to run through the files--------------------

Sub OrganizeFiles(path)

dim fs, folder, file, item, url

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)

'Display the target folder and info.

'Display a list of sub folders.

for each item in folder.SubFolders

'Display a list of files.

for each item in folder.Files

CreateFolder item.Name,item.DateLastModified
CopyToFolder item.path,item.Name,item.DateLastModified


set fs = Nothing

end sub


Text Message Notification

Nowadays email mailing lists are not nearly as popular or hip as text message lists.  There are service providers out there that charge you an arm and a leg for text messaging.  There are also free services like Twitter but it requires you join the twitter network.  I needed a quick an easy way to notify our technicans and managers of technology issues or outages.  I wrote this simple web application that allows you to send text messages based on subscribed categories. It is built in Dreamweaver using Classic ASP and runs on a Microsoft Access Database.

License: Open Source (GNU General Public License)

Demo Site
password: password

Note: This demo is intended to display the features and user interface. The ability to update the database has been removed.

Installation: On a windows server, unzip, upload, change permissions on the database to write and you're good to go.

1) Set your Categories
Categories are items that a user may want to be notifed about. 
  • ITS - You may want to set up your categories as different technology items (servers, phones, email, etc...)
  • Clubs & Services - You may want to set up your categories for different clubs and services services and notify students or users of upcoming events. 
  • Emergency - Categories can be different types of emergency notification.  However, given this is running off of an access database I wouldn't run it with more than 100 users.
2) Create Users

3) Select which users should be notified about which categories.

How it Works:  It's actually very simple.  It uses CDOSYS to send emails to the user's cell phone provider text message service. 

Enjoy and donations to my college fund are welcome =)