python使用xauth方式登录饭否网然后发消息
开发环境:python版本2.X
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# 适合python版本:2.Ximport sys, urllib, re
import oauth.oauth as oauth
from urllib2 import Request, urlopenstatus = 'hello world !' # send message
consumer_key = '...' # api key
consumer_secret = '...' # api secretaccess_token_url = 'http://fanfou.com/oauth/access_token'
verify_url = 'http://api.fanfou.com/account/verify_credentials.xml'
post_url = 'http://api.fanfou.com/statuses/update.xml'def request_to_header(request, realm=''):
"""Serialize as a header for an HTTPAuth request."""
auth_header = 'OAuth realm="%s"' % realm
# Add the oauth parameters.
if request.parameters:
for k, v in request.parameters.iteritems():
if k.startswith('oauth_') or k.startswith('x_auth_'):
auth_header += ', %s="%s"' % (k, oauth.escape(str(v)))
return {'Authorization': auth_header}# get username and password from command line
username = sys.argv[1]
passwd = sys.argv[2]consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
params = {}
params["x_auth_username"] = username
params["x_auth_password"] = passwd
params["x_auth_mode"] = 'client_auth'
request = oauth.OAuthRequest.from_consumer_and_token(consumer,
http_url=access_token_url,
parameters=params)
signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
request.sign_request(signature_method, consumer, None)
headers=request_to_header(request)resp = urlopen(Request(access_token_url, headers=headers))
token = resp.read()
print token # access_token got
m = re.match(r'oauth_token=(?P<key>[^&]+)&oauth_token_secret=(?P<secret>[^&]+)', token)
if m:
oauth_token = oauth.OAuthToken(m.group('key'), m.group('secret'))
params['status']=status
request = oauth.OAuthRequest.from_consumer_and_token(consumer,
http_method='POST',
token=oauth_token,
http_url=post_url,
parameters=params)
request.sign_request(signature_method, consumer, oauth_token)
headers=request_to_header(request)
resp = urlopen(Request(url=post_url, data=urllib.urlencode({'status':status}), headers=headers))
print resp.read()
您可能感兴趣的文章:
- python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)
- python使用rsa加密算法模块模拟新浪微博登录
- python实现人人网登录示例分享
- python模拟登录百度代码分享(获取百度贴吧等级)
- python模拟登录百度贴吧(百度贴吧登录)实例
- Python(Tornado)模拟登录小米抢手机
- 利用webqq协议使用python登录qq发消息源码参考
- Python 用户登录验证的小例子
- 使用python实现baidu hi自动登录的代码
- python登录QQ邮箱发信的实现代码
- python cookielib 登录人人网的实现代码
- ssh批量登录并执行命令的python实现代码
- Python使用Socket(Https)Post登录百度的实现代码
- python远程登录代码
- 用python登录Dr.com思路以及代码分享
- python使用xauth方式登录饭否网然后发消息
- 使用python来玩转ensp~系列1-telnet方式登录管理设备
- 利用webqq协议使用python登录qq发消息源码参考
- 不用python 微博sdk, 使用python裸体登录微博, 然后发一条微博, 再退出微博
- 利用webqq协议使用python登录qq发消息源码参考
- 利用webqq协议使用python登录qq发消息
- 使用Python调用工作目录下所有快捷方式
- 此数据库没有有效所有者,因此无法安装数据库关系图支持对象。若要继续,请首先使用“数据库属性”对话框的“文件”页或 ALTER AUTHORIZATION 语句将数据库所有者设置为有效登录名,然后再添加数据库关系图支持对象。
- python方式下自动登录51cto
- jQuery入门学习二:使用jQuery方式实现异步登录验证
- xp底下成功使用ssh登录ubuntu linux(采用密钥方式)
- Communicator使用TLS方式登录提示证书验证失败问题的解决
- 使用Python模拟登录QQ邮箱获取QQ好友列表
- 黄聪:使用 Python 登录网站
- 使用SSH密钥方式登录Linux
- 易宝典文章——如何设定OWA登录时只使用用户名加密码的方式
- 使用Python为程序添加右键菜单打开方式
- Video : 将使用AD认证的SharePoint网站配置为表单方式登录
- 如何使用SecureCRT6.6.2通过SSH方式登录Ubuntu系统?
- [导入]Sql Server2005 express使用SqL方式登录