Permalink
Browse files

qqweibo: add OAuth2 handler; example: fix some example

  • Loading branch information...
1 parent 9f78ae7 commit 34307133219f37f79aef62de5fc1030c482a99a9 @andelf committed Mar 17, 2013
Showing with 19 additions and 17 deletions.
  1. +9 −11 examples/example-auth.py
  2. +5 −3 examples/example-user.py
  3. +2 −1 qqweibo/__init__.py
  4. +3 −2 qqweibo/auth.py
@@ -12,8 +12,9 @@
import sys
sys.path.insert(0, '..')
import webbrowser
-from qqweibo import OAuthHandler, API, JSONParser
-
+from qqweibo import API, JSONParser
+from qqweibo import OAuth2_0_Handler as AuthHandler
+import secret
# for py3k
try:
@@ -22,17 +23,13 @@
pass
-API_KEY = 'your key'
-API_SECRET = 'your secret'
-
-if API_KEY.startswith('your'):
- print ('You must fill API_KEY and API_SECRET!')
- webbrowser.open("http://open.t.qq.com/apps_index.php")
- raise RuntimeError('You must set API_KEY and API_SECRET')
+API_KEY = secret.apiKey
+API_SECRET = secret.apiSecret
+CALLBACK_URL = 'http://fledna.duapp.com/query'
-auth = OAuthHandler(API_KEY, API_SECRET)
+auth = AuthHandler(API_KEY, API_SECRET, CALLBACK_URL)
# or you can use callback url
-# auth = OAuthHandler(API_KEY, API_SECRET,
+# auth = AuthHandler(API_KEY, API_SECRET,
# callback="http://localhost:5000/callback")
# will be callbackurl?oauth_token=[OAUTH_TOKEN]&oauth_verifier=[VERIFIER]
@@ -44,6 +41,7 @@
access_token = auth.get_access_token(verifier)
+print access_token
# = Save Token =
token = access_token.key
tokenSecret = access_token.secret
@@ -12,7 +12,8 @@
sys.path.insert(0, "..")
import webbrowser
-from qqweibo import OAuthHandler, API
+from qqweibo import API
+from qqweibo import OAuth2_0_Handler as AuthHandler
API_KEY = 'your key'
API_SECRET = 'your secret'
@@ -22,8 +23,10 @@
webbrowser.open("http://open.t.qq.com/apps_index.php")
raise RuntimeError('You must set API_KEY and API_SECRET')
+CALLBACK_URL = 'http://fledna.duapp.com/query'
+
+auth = AuthHandler(API_KEY, API_SECRET, CALLBACK_URL)
-auth = OAuthHandler(API_KEY, API_SECRET)
token = YOUR TOKEN HERE
tokenSecret = YOUR TOKEN_SECRET HERE
@@ -65,4 +68,3 @@
for t in ret.timeline(reqnum=3):
print (t.text)
-
View
@@ -4,7 +4,7 @@
# See LICENSE for details.
# Time-stamp: <2011-11-01 17:44:15 wangshuyu>
-#from qqweibo.auth import OAuthHandler
+from qqweibo.auth import OAuth1_0_Handler, OAuth2_0_Handler, OpenId_OpenKey_Handler
from qqweibo.api import API
from qqweibo.parsers import (ModelParser, JSONParser, XMLRawParser,
XMLDomParser, XMLETreeParser)
@@ -13,6 +13,7 @@
__all__ = ['API', 'QWeiboError', 'version',
+ 'OAuth1_0_Handler', 'OAuth2_0_Handler', 'OpenId_OpenKey_Handler',
'XMLRawParser', 'XMLDomParser', 'XMLETreeParser',
'ModelParser', 'JSONParser',
'MemoryCache', 'FileCache']
View
@@ -239,7 +239,7 @@ def authorize_request(self, url, method, headers, parameters):
query["wbversion"] = "1"
query = query.items()
- query = [(str(k), to_utf8(v)) for k,v in query]
+ query = [(str(k), convert_to_utf8_bytes(v)) for k,v in query]
query.sort()
uri = urlparse.urlparse(url)[2] # url path
raw = '&'.join(method, urlencode(uri), urlencode('&'.join(("%s=%s" % kv) for kv in query)))
@@ -248,7 +248,8 @@ def authorize_request(self, url, method, headers, parameters):
#return binascii.b2a_base64(hashed.digest())[:-1]
# fix py3k, str() on a bytes obj will be a "b'...'"
sig = binascii.b2a_base64(hashed.digest())[:-1]
- print ret
+ print sig
+ query.append(("sig", sig))
return ret.decode('ascii')
if method == 'POST':

0 comments on commit 3430713

Please sign in to comment.