Not a zope post, but a python + google friend connect /opensocial post.
For those not in the know, google released Friend Connect a while ago, and recently the friend connect APIs.
Here's how to do stuff with python and the python opensocial client.
First off, make your site social by getting the necessary codes at google friend connect
Once done, click "For Developers" at google friend connect, go to the REST API and look for your Consumer key and consumer secret. We need this to authenticate our site.
Now, get the python opensocial client from google code svn. Version 0.1 don't work, afaik.
Define our 2-legged oauth:
config = ContainerConfig(oauth_consumer_key='*:021503737115490xxx',
oauth_consumer_secret='YLGq2tT60xxxx',
server_rest_base='http://www.google.com/friendconnect/api/')
Get our container, ie our social site:
container = ContainerContext(config)
Get the owner:
owner = container.fetch_person('@owner')
DEBUG:root:URL: GET http://www.google.com/friendconnect/api/people/@owner/@self?opensocial_method=GET&oauth_nonce=31928xxx&oauth_timestamp=1237351810&oauth_consumer_key=%2A%3A02150373xxx3&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=f6bLw%2FcLJChxK0Axxx%3D
HEADERS: {}
POST: None
DEBUG:root:Status: 200
Content: {"entry":{"id":"0215037371154900xxxx","name":{"formatted":"xxx","honorificPrefix":"","additionalName":"","familyName":"","givenName":"xxxx","honorificSuffix":""},"displayName":"xxx"}}
For GFC, we're interested in @owner (that's our social site), @viewer (member visiting our social site).
For more information, see google code
Getting our sites members:
friends = container.fetch_friends('@owner')
We can also get user profile and their friends:
f1 = container.fetch_person('10687053440612809xxx')
DEBUG:root:URL: GET http://www.google.com/friendconnect/api/people/10687053440612809xxx/@self?xoauth_requestor_id=106870534406128xxx&opensocial_method=GET&oauth_nonce=39529384&oauth_timestamp=1237360306&oauth_consumer_key=%2A%3A0215037371154900xxx&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_signature=1A9uDs8Gx76SXcxaitzFoMoxxx3D
HEADERS: {}
POST: None
DEBUG:root:Status: 200
Content: {"entry":{"id":"10687053440612809xxx","thumbnailUrl":"http://www.google.com/friendconnect/profile/picture/RS0TMYQNLWYTQoDOy628qKHweOxhEM2DKXh9Mj-4EtDGks4qJJwaMmhPAxov5VFafWugk1-IWsVgG4Li4VTsn2Tt6t9ecS1LrsARxaUprajTtIpbpyzuWQ","photos": [{"value":"http://www.google.com/friendconnect/profile/picture/RS0TMYQNLWYTQoDOy628qKHweOxhEM2DKXh9Mj-4EtDGks4qJJwaMmhPAxov5VFafWugk1-IWsVgG4Li4VTsn2Tt6t9ecS1LrsARxaUprajTtIpbpyzuWQ","type":"thumbnail"}],"displayName":"akuler"}}
f1f = container.fetch_friends('10687053440612809xxx') #friends of f1
The only thing I can't figure out now is getting all the activities; for the site and for friends, and posting activities, as done via javascript library in the google sample site..
Which leads me to another way accessing opensocial data; using the cookies.
Everytime a user log in GFC site, a cookie with id fcauth[siteid] is set. Get the token set in the cookie to do stuff with opensocial data.
Here's how to get site information:
import urllib
import simplejson as sj
op = urllib.urlopen('http://www.google.com/friendconnect/api/people/@owner/@self?fcauth=cookie_content')
sj.load(op)
{'entry': {'displayName': 'myzope',
'id': '13049012993404024759',
'name': {'additionalName': '',
'familyName': '',
'formatted': 'myzope',
'givenName': 'myzope',
'honorificPrefix': '',
'honorificSuffix': ''}}}
Getting site members:
op = urllib.urlopen('http://www.google.com/friendconnect/api/people/@owner/@all?fcauth=cookie_content')
sj.load(op)
{'entry': [{'displayName': 'kedai',
'id': '1792224923984047xxxx',
'photos': [{'type': 'thumbnail',
'value': 'http://www.google.com/friendconnect/profile/picture/m0P8MS_9Rtr0cC_b0KH1JhQelQRnLAJ8AhH0WfUFwIwLDXuJzVtqEQnyzYGVDUeeZs7P9zPgHdY5Sjx0JwQNmzdYr1iaLwbjtqSry6O-3nXioabWPA3x99U80lUtJe6tC57kAP--01qeYg7GEvVk07x5f1ZyvqMDX_1nC0hz1cbqyMUmEY8aqls26WVHdD2edoouaQlEBXRsdWvuJgskXUqJvM7_HWJtgolKbKli8vEHqLVHh48uYAG8GVl1m5BuyvRciibgzqmhKQ5A7_LeGA'}],
'thumbnailUrl': 'http://www.google.com/friendconnect/profile/picture/m0P8MS_9Rtr0cC_b0KH1JhQelQRnLAJ8AhH0WfUFwIwLDXuJzVtqEQnyzYGVDUeeZs7P9zPgHdY5Sjx0JwQNmzdYr1iaLwbjtqSry6O-3nXioabWPA3x99U80lUtJe6tC57kAP--01qeYg7GEvVk07x5f1ZyvqMDX_1nC0hz1cbqyMUmEY8aqls26WVHdD2edoouaQlEBXRsdWvuJgskXUqJvM7_HWJtgolKbKli8vEHqLVHh48uYAG8GVl1m5BuyvRciibgzqmhKQ5A7_LeGA'}],
'startIndex': 0,
'totalResults': 1}
Getting viewer information:
op = urllib.urlopen('http://www.google.com/friendconnect/api/people/@viewer/@self?fcauth=cookie_content')
sj.load(op)
{'entry': {'displayName': 'kedai',
'id': '17922249239840471xxx',
'photos': [{'type': 'thumbnail',
'value': 'http://www.google.com/friendconnect/profile/picture/m0P8MS_9Rtr0cC_b0KH1JhQelQRnLAJ8AhH0WfUFwIwLDXuJzVtqEQnyzYGVDUeeZs7P9zPgHdY5Sjx0JwQNmzdYr1iaLwbjtqSry6O-3nXioabWPA3x99U80lUtJe6tC57kAP--01qeYg7GEvVk07x5f1ZyvqMDX_1nC0hz1cbqyMUmEY8aqls26WVHdD2edoouaQlEBXRsdWvuJgskXUqJvM7_HWJtgolKbKli8vEHqLVHh48uYAG8GVl1m5BuEsQ4HQ27PT_1yUnKynK_hw'}],
'thumbnailUrl': 'http://www.google.com/friendconnect/profile/picture/m0P8MS_9Rtr0cC_b0KH1JhQelQRnLAJ8AhH0WfUFwIwLDXuJzVtqEQnyzYGVDUeeZs7P9zPgHdY5Sjx0JwQNmzdYr1iaLwbjtqSry6O-3nXioabWPA3x99U80lUtJe6tC57kAP--01qeYg7GEvVk07x5f1ZyvqMDX_1nC0hz1cbqyMUmEY8aqls26WVHdD2edoouaQlEBXRsdWvuJgskXUqJvM7_HWJtgolKbKli8vEHqLVHh48uYAG8GVl1m5BuEsQ4HQ27PT_1yUnKynK_hw'}}
Getting site activities:
op = urllib.urlopen('http://www.google.com/friendconnect/api/activities/@owner/@friends/@app?fcauth=cookie_content')
Next steps: build something, with zope if possible.
Trackback is http://myzope.kedai.com.my/blogs/kedai/231/tbping
