One main feature in Lotus Connections 3.0 is the asymmetric follow of someone (like twitter). The API documentation is here. Since sample code is always better here’s a HTTP GET python snippet to lookup the userid, given an email and then a quick HTTP POST to follow that user.
#!/usr/bin/python
import sys,urllib,urllib2,traceback,base64
from xml.dom import minidom
xml_data_header = """
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<category term="resource-follow" scheme="http://www.ibm.com/xmlns/prod/sn/type"></category>
<category term="profiles" scheme="http://www.ibm.com/xmlns/prod/sn/source"></category>
<category term="profile" scheme="http://www.ibm.com/xmlns/prod/sn/resource-type"></category>
<category term="
""".strip()
xml_data_footer = """
" scheme="http://www.ibm.com/xmlns/prod/sn/resource-id"></category>
</entry>
""".strip()
if len(sys.argv) != 4:
print 'Usage: follow <userid> <password> <email-of-user-to-follow>'
sys.exit(1)
base64string = base64.encodestring('%s:%s' % (sys.argv[1], sys.argv[2]))[:-1]
def getUuidForUser(email):
uri = "https://w3-connections.ibm.com/profiles/atom/profile.do?format=lite&email=%s" % email
req = urllib2.Request(uri)
req.add_header('Content-type','application/atom+xml')
req.add_header('Authorization', "Basic %s" % base64string)
dom = minidom.parse(urllib2.urlopen(req))
element = dom.getElementsByTagNameNS('http://www.ibm.com/xmlns/prod/sn', 'userid')[0]
return element.firstChild.data
def followUser(uuid):
uri = 'https://w3-connections.ibm.com/profiles/follow/atom/resources'
query_string_values = {'source': 'profiles', 'type' : 'profile'}
payload = '%s%s%s' % (xml_data_header, uuid, xml_data_footer)
try :
if query_string_values:
uri = ''.join([uri, '?', urllib.urlencode(query_string_values)])
req = urllib2.Request(uri, data=payload)
req.add_header('Content-type','application/atom+xml')
req.add_header('Authorization', "Basic %s" % base64string)
response = urllib2.urlopen(req)
return response.read()
except urllib2.HTTPError, error:
return error.read()
print followUser(getUuidForUser(sys.argv[3]))
