今天心血來潮想寫個列出 Plurk 內容的功能,翻開 Plurk API 一看,找到

了這個 API 「 /API/Profile/getPublicProfile 」,需要傳入 api_key 與

user_id  疑 o_O?user_id 要如何取得呢?連過去Plurk官網介紹一個非

官方新手入門手冊:http://weedyc.pixnet.net/blog/post/23311875

裡面提到一個 噗浪 UID 查詢工具: http://puid.daydream.idv.tw/

可直接查詢到 UID,很方便

2010-03-18_115238.jpg

這時再回頭看了一下 Plurk API 發現

/API/UserSearch/search 可以查到使用者資訊,那就來寫個程式測測吧!

 

import urllib, urllib2, cookielib, json

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
api_key = '你的 API Key'
get_api_url = lambda x: 'http://www.plurk.com/API%s' % x
encode = urllib.urlencode


fp=opener.open(get_api_url('/UserSearch/search'),
                 encode({'query': '你要查詢的使用者',                        
                         'api_key': api_key}))
                                            
data=json.loads(fp.read())
for i in data['users']:
    print 'nick name:',i['nick_name']
    print 'full name:',i['full_name']
    print 'uid:',i['id'],'\n'

 

儲存成 test2.py 後,執行 Python test2.py

執行結果

2010-03-18_120333.jpg

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()