def qqauth(request): try: auth = OAuthHandler(settings.QQ_APP_KEY, settings.QQ_APP_SECRET, settings.QQ_CALLBACK) url = auth.get_authorization_url() request.session['qqauth'] = auth return HttpResponseRedirect(url) except Exception as e: logging.error(e) return HttpResponseRedirect('')
def get_api(): import sys, os.path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from qqweibo import OAuthHandler, API c = get_conf() try: o = OAuthHandler(c['consumer_key'], c['consumer_secret']) o.setToken(c['access_token_key'], c['access_token_secret']) except KeyError, e: sys.stderr.write("qq: you should run get_oauthed.py first.\n")
def main(): c = get_conf() o = OAuthHandler(c["consumer_key"], c["consumer_secret"]) c["authorization_url"] = o.get_authorization_url() c["request_token"] = o.request_token print c["authorization_url"] verifier = raw_input("click the url above, then input the verifier: ") verifier = verifier.strip() c["verifier"] = verifier try: access_token = o.get_access_token(verifier) c["access_token_key"] = access_token.key c["access_token_secret"] = access_token.secret c["access_token"] = access_token.to_string() set_conf(c) print "oauth succeeded" except: print "oauth failed"
def main(): c = get_conf() o = OAuthHandler(c['consumer_key'], c['consumer_secret']) c['authorization_url'] = o.get_authorization_url() c['request_token'] = o.request_token print c['authorization_url'] verifier = raw_input('click the url above, then input the verifier: ') verifier = verifier.strip() c['verifier'] = verifier try: access_token = o.get_access_token(verifier) c['access_token_key'] = access_token.key c['access_token_secret'] = access_token.secret c['access_token'] = access_token.to_string() set_conf(c) print 'oauth succeeded' except: print 'oauth failed'
class AlfredQQWeibo(): auth = OAuthHandler(API_KEY, API_SECRET) setting = {} def load_setting(self): with open('setting.pickle', 'rb') as f: self.setting = pickle.load(f) def save_setting(self): with open('setting.pickle', 'wb') as f: pickle.dump(self.setting, f) def verify(self): auth_url = self.auth.get_authorization_url() requestToken = self.auth.request_token.key requestTokenSecret = self.auth.request_token.secret if (requestToken != None and requestToken.count > 0): print "确认授权后,运行:\n \"qwb pin {授权码}\"" self.setting['request_token'] = requestToken self.setting['request_token_secret'] = requestTokenSecret self.save_setting() webbrowser.open(auth_url) else: print 'ERROR, try again pls.' def getAccessToken(self, pin): self.load_setting() self.auth.set_request_token(self.setting['request_token'], self.setting['request_token_secret']) access_token = self.auth.get_access_token(pin) if (access_token.key != None and access_token.secret != None and access_token.key.count > 0 and access_token.secret.count > 0): self.setting['access_token'] = access_token.key self.setting['access_token_secret'] = access_token.secret self.save_setting() print '验证成功.运行"qwb {message}",发送微博' else: print "ERROR, try again pls." def tweet(self, message): self.load_setting() self.auth.set_request_token(self.setting['request_token'], self.setting['request_token_secret']) self.auth.set_access_token(self.setting['access_token'], self.setting['access_token_secret']) api = API(self.auth, parser=ModelParser()) ret = api.tweet.add(message, clientip='127.0.0.1') if (ret): tw = api.tweet.show(ret.id) print('发送成功:微博ID={0.id}\n用户名={0.nick}\n内容={0.text}'.format(tw))
# simple use from qqweibo import OAuthHandler, API, JSONParser, ModelParser from qqweibo.utils import timestamp_to_str import urllib, urllib2, http_helper a = OAuthHandler('801486043', 'cd0a763d5f7d8be4f588b0f6f290fb06') a = OAuthHandler('801486692', '35499dde285b599841fcee05aee4e28b') a = OAuthHandler('801486694','122efd9274999d8eb06b185501611ca0') aaaaa = OAuthHandler('801486696','c45b2b1afb0eae1e64466f7c9fd36319') aaaaa = OAuthHandler('801486704','f8a0cb0327d53a71aba609707c3ea239') aaaaa = OAuthHandler('801486706','ccb88ca0bd2d2ab59465abf45818567e') # use this url = a.get_authorization_url() print 'authorization url:' + url verifier = raw_input('PIN: ').strip() a.get_access_token(verifier) # or directly use: #token = 'your token' #tokenSecret = 'your secret' #a.setToken(token, tokenSecret) '''rhhgjkli''' api = API(a) #me = api.user.info() #print me.name, me.nick, me.location #nba = api.user.userinfo('NBA')
#! /usr/bin/env python #coding=utf-8 from config import * from qqweibo import OAuthHandler, API, JSONParser, ModelParser from utils import store_category, weibo_logger, store_error API_KEY = '801322882' API_SECRET = '0f4b0f472813b31c23720623014e22e9' a = OAuthHandler(API_KEY, API_SECRET) def get_token(): print a.get_authorization_url() verifier = raw_input('PIN: ').strip() print a.get_access_token(verifier) # or directly use: #token = 'e9fc735b76ba4e75a6ebaefe61ee66fc' token = 'd169abff38d747cfa8bdb21123577482' #tokenSecret = 'ec07bda1b332156d1554470893b16b6d' tokenSecret = '25d60b4c67c488a4d5291dcb9bd43fd8' a.setToken(token, tokenSecret) api = API(a) QQ_WEIBO_INFO_SOURCE_ID = 7
def getApi(token,secret): auth = OAuthHandler(webSetting.qqconsumer_key, webSetting.qqconsumer_secret) auth.setToken(token, secret) api = API(auth) return api
# simple use from qqweibo import OAuthHandler, API, JSONParser, ModelParser from qqweibo.utils import timestamp_to_str import urllib, urllib2, http_helper import os a = OAuthHandler('801486043', 'cd0a763d5f7d8be4f588b0f6f290fb06') a = OAuthHandler('801486692', '35499dde285b599841fcee05aee4e28b') a = OAuthHandler('801486694','122efd9274999d8eb06b185501611ca0') a = OAuthHandler('801486696','c45b2b1afb0eae1e64466f7c9fd36319') aaaaa = OAuthHandler('801486704','f8a0cb0327d53a71aba609707c3ea239') aaaaa = OAuthHandler('801486706','ccb88ca0bd2d2ab59465abf45818567e') # Get the keys of user name users_dict = dict() aa = open('relations_new', 'r') users = aa.readlines() aa.close() nicks = dict() for line in users: line = line.replace('\n', ''):q line = line.decode('utf-8') user_nick, friend = line.split('::::') user,nick = user_nick.split(',') nicks[user] = nick friend_name, friend_nick = friend.split(',') nicks[friend_name] = friend_nick if user not in users_dict: users_dict[user] = [] users_dict[user].append(friend_name)
import sys sys.path.insert(0, "..") import webbrowser from qqweibo import OAuthHandler, API 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') auth = OAuthHandler(API_KEY, API_SECRET) token = YOUR TOKEN HERE tokenSecret = YOUR TOKEN_SECRET HERE auth.setToken(token, tokenSecret) # this time we use ModelParser() api = API(auth) # ModelParser is the default option """ Avaliable API: Do to refer api.doc.rst api.user.info api.user.otherinfo