1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import oauth2 as oauth
	import urlparse

	OAUTH_REQUEST_TOKEN = 'http://www.plurk.com/OAuth/request_token'
	OAUTH_ACCESS_TOKEN = 'http://www.plurk.com/OAuth/access_token'

	def get_request_token(app_key, app_secret):
		consumer = oauth.Consumer(app_key, app_secret)
		client = oauth.Client(consumer)
		params = { 'oauth_signature_method': 'HMAC-SHA1',
				   'oauth_nonce': oauth.generate_nonce(),
				   'oauth_timestamp': oauth.generate_timestamp() }
		req = oauth.Request.from_consumer_and_token(consumer=consumer,
				   http_method='POST', http_url=OAUTH_REQUEST_TOKEN,
				   parameters=params, is_form_encoded=True)
		req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, None)
		response = client.request(OAUTH_REQUEST_TOKEN, method='POST', headers=req.to_header())
		return urlparse.parse_qs(response)

	def get_access_token(app_key, app_secret, oauth_token, oauth_token_secret, oauth_verifier):
		consumer = oauth.Consumer(app_key, app_secret)
		token = oauth.Token(oauth_token, oauth_token_secret)
		client = oauth.Client(consumer, token)
		params = { 'oauth_signature_method': 'HMAC-SHA1',
				   'oauth_nonce': oauth.generate_nonce(),
				   'oauth_timestamp': oauth.generate_timestamp(),
				   'oauth_token': oauth_token,
				   'oauth_token_secret': oauth_token_secret,
				   'oauth_verifier': oauth_verifier }
		req = oauth.Request.from_consumer_and_token(consumer=consumer, token=token,
				   http_method='POST', http_url=OAUTH_ACCESS_TOKEN,
				   parameters=params, is_form_encoded=True)
		req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
		response = client.request(OAUTH_ACCESS_TOKEN, method='POST', headers=req.to_header())
		return urlparse.parse_qs(response)

	def getOwnProfile(app_key, app_secret, oauth_token, oauth_token_secret):
		api_url = 'http://www.plurk.com/APP/Profile/getOwnProfile'
		consumer = oauth.Consumer(app_key, app_secret)
		token = oauth.Token(oauth_token, oauth_token_secret)
		client = oauth.Client(consumer, token)
		params = { 'oauth_signature_method': 'HMAC-SHA1',
				   'oauth_nonce': oauth.generate_nonce(),
				   'oauth_timestamp': oauth.generate_timestamp(),
				   'oauth_token': oauth_token }
		req = oauth.Request.from_consumer_and_token(consumer=consumer, token=token,
				   http_method='GET', http_url=api_url, parameters=params)
		req.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
		response = client.request(api_url, method='GET', headers=req.to_header())
		return response
	 [loveyou]