I have a working GET using 2-legged oauth2 in python. Here is the WORKING GET code:
the imports:
import oauth2
import urllib #for
This is the code I have been using to make a POST request to Twitter using oauth2. Hope it helps you to figure out the syntax.
import oauth2 as oauth, urllib
def oauth_req(url, key, secret, http_method="POST", post_body=None, http_headers=None):
CONSUMER_KEY = YOUR_KEY
CONSUMER_SECRET = YOUR_SECRET
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
token = oauth.Token(key=key, secret=secret)
client = oauth.Client(consumer, token)
resp, content = client.request(
url,
method=http_method,
body=urllib.urlencode({'status': post_body}),
headers=http_headers,
force_auth_header=True,
)
return content
oauth_req('http://api.twitter.com/1/statuses/update.json', KEY, SECRET, post_body=MESSAGE)