跳到主要內容

發表文章

目前顯示的是有「Python」標籤的文章

Python 使用 plurk API 的中文處理

以下取自 http://www.plurk.com/API 之中的範例做些小小的調整 注意 api_key , 以及帳密的部份要改成自己的就可以測試POST訊息啦 其他的使用就請參考官網中的 Table of contents 的說明啦 #------------- code start ---------------- # -*- coding:utf-8 -*- # 上面這一行一定要加, 否則一跑就出現Non Ascii的錯誤 # 修改自 http://www.plurk.com/API/ 中的python範例 import urllib, urllib2, cookielib opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) api_key = 'dKkIdUCoHo7vUDPjd3zE0bRvdm5a9sQi' get_api_url = lambda x: 'http://www.plurk.com/API%s' % x encode = urllib.urlencode #--- Requests ---------------------------------------------- fp = opener.open(get_api_url('/Users/login'), encode({'username': 'user_x', 'password': 'user_x_pw', 'api_key': api_key})) print fp.read() # unicode 中文字 msg = u'中文字測試' fp = opener.open(get_api_url('/Timeline/plurkAdd'), encode({'content': msg.encode("utf8"), ...