Created
February 20, 2014 02:54
-
-
Save Kevinstronger/9106262 to your computer and use it in GitHub Desktop.
饭否实验代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# - * - coding: UTF-8 - * - | |
import json | |
import urllib | |
import oauth2 as oauth | |
# 此行用于获取 CONSUMER_KEY、CONSUMER_SECRET 等常数 | |
from config import * | |
consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET) | |
token = oauth.Token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
client = oauth.Client(consumer, token) | |
data = { | |
'status': 'test', | |
#'source': SOURCE | |
} | |
body = urllib.urlencode(data) | |
request = oauth.Request.from_consumer_and_token( | |
consumer, token=token, | |
http_method='POST', | |
http_url=url, | |
parameters=data) | |
request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token) | |
import httplib | |
conn = httplib.HTTPConnection('api.fanfou.com:80') | |
headers = { | |
'content-type': 'application/x-www-form-urlencoded', | |
} | |
conn.request('POST', '/statuses/update.json', | |
body=request.to_postdata(), headers=headers) | |
resp = conn.getresponse() | |
# 此处得到 Invalid consumer key | |
print resp.read() | |
headers = { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
} | |
conn.request('POST', '/statuses/update.json', | |
body=request.to_postdata(), headers=headers) | |
resp = conn.getresponse() | |
# 此处成功发送 | |
print resp.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment