Example #1
0
class ClientHelper():

    # Initiate the Douban API v2.0 client with OAuth.
    def __init__( self ):
        key = '022e300c79c18fc7068a90256d44af55'
        secret = '11c8bcbac80e8085'
        callback = 'http://www.douban.com'
        scope = 'douban_basic_common,community_basic_user'
        self.client = DoubanClient( key, secret, callback, scope )
        self.client.auth_with_token( '23f8580710490aad6be9081530db2007' )
Example #2
0
class MyDouban:
    def __init__(self):
        self.clent = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        self.clent.auth_with_token(TOKEN)

    def search_movie(self, keyword):
        q = ''
        for kw in keyword:
            q += kw + ''
        return self.clent.movie.search(q)
Example #3
0
class MyDouban:
    def __init__(self):
        self.clent = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        self.clent.auth_with_token(TOKEN)

    def search_movie(self, keyword):
        q = ""
        for kw in keyword:
            q += kw + ""
        return self.clent.movie.search(q)
Example #4
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token) 
    else:
        print 'Go to the following link in your browser:' 
        print client.authorize_url

        code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print client.client.token
    return client
Example #5
0
def get_client():

    from douban_client import DoubanClient
    API_KEY = os.environ.get('DOUBAN_API_KEY')
    API_SECRET = os.environ.get('DOUBAN_API_SECRET')
    your_redirect_uri = ''
    SCOPE = 'bouban_basic_common, community_basic_user, shuo_basic_r, shuo_basic_w'

    TOKEN_CODE = os.environ.get('DOUBAN_TOKEN_CODE')

    client = DoubanClient(API_KEY, API_SECRET, your_redirect_uri, SCOPE)

    client.auth_with_token(TOKEN_CODE)

    return client
Example #6
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token) 
    else:
        print 'Go to the following link in your browser:' 
        print client.authorize_url

        code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print client.client.token
    return client
Example #7
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token)
    else:
        print "Go to the following link in your browser:"
        print client.authorize_url

        code = raw_input("Enter the verification code and hit ENTER when you're done:")
        client.auth_with_code(code)
        print "token code:", client.token_code
        print "refresh token code:", client.refresh_token_code
    return client
Example #8
0
class Note4stDouban:
    def __init__(self, user_json_file=None):
        """douban client for note4st
              user_json_file - solved on register
        """
        self.client = None
        self.user = DoubanUser()
        self.is_login = False
        if user_json_file:
            self.user.load(open(user_json_file))

    def register(self, auth_code):
        """douban client for note4st
              user_json_file - solved on register
        """
        self.client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        self.client.auth_with_code(auth_code)
        self.user.registered(
            self.client.user.me,
            self.client.user.access_token.token,
            self.client.user.access_token.refresh_token,
            self.client.user.access_token.expires_in,
            self.client.user.access_token.expires_at,
        )
        self.user.save2file(self.user.name)
        self.is_login = True

    def login(self, email=None, password=None, token=None):
        if not self.client:
            self.client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        if token:
            self.client.auth_with_token(token)
            self.client.auth_with_token(token)
        else:
            self.client.auth_with_password(email, password)
            self.user.refresh_token = self.client.refresh_token_code
        self.user.uid = self.client.user.me['uid']
        self.is_login = True
def get_client_v2():
    client = DoubanClient(key, secret, callback, SCOPE)
    if expires_at:
        expires_time = int(expires_at)

    if token:
        now_time = int(time.time())
        remaining_seconds = expires_time - now_time
        #print 'remains: ' + str(remaining_seconds)
        if remaining_seconds > 3600:
            client.auth_with_token(token)
        else:
            client.refresh_token(refresh_token)
            config.set('INFO', 'token', client.token_code)
            config.set('INFO', 'refresh_token', client.refresh_token_code)
            config.set('INFO', 'expires_at', client.expires_at)
            with open('test_config.cfg', 'wb') as configfile:
                config.write(configfile)
    else:
        print_('Go to the following link in your browser:')
        print_(client.authorize_url)

        code = input(
            'Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print_('token code:', client.token_code)
        print_('refresh token code:', client.refresh_token_code)
        print_('expires at:', client.expires_at)
        print type(client.expires_at)
        config.set('INFO', 'token', client.token_code)
        config.set('INFO', 'refresh_token', client.refresh_token_code)
        config.set('INFO', 'expires_at', client.expires_at)
        with open('test_config.cfg', 'wb') as configfile:
            config.write(configfile)
        #pdb.set_trace()

    return client
def get_client_v2():
    client = DoubanClient(key, secret, callback, SCOPE)
    if expires_at:
        expires_time = int(expires_at)

    if token:
        now_time = int(time.time())
        remaining_seconds = expires_time - now_time
        #print 'remains: ' + str(remaining_seconds)
        if remaining_seconds > 3600:
            client.auth_with_token(token)
        else:
            client.refresh_token(refresh_token)   
            config.set('INFO', 'token', client.token_code)
            config.set('INFO', 'refresh_token', client.refresh_token_code)
            config.set('INFO', 'expires_at', client.expires_at)
            with open('test_config.cfg', 'wb') as configfile:
                config.write(configfile)
    else:
        print_('Go to the following link in your browser:')
        print_(client.authorize_url)

        code = input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print_('token code:', client.token_code)
        print_('refresh token code:', client.refresh_token_code)
        print_('expires at:', client.expires_at)
        print type(client.expires_at)
        config.set('INFO', 'token', client.token_code)
        config.set('INFO', 'refresh_token', client.refresh_token_code)
        config.set('INFO', 'expires_at', client.expires_at)
        with open('test_config.cfg', 'wb') as configfile:
            config.write(configfile)
        #pdb.set_trace()

    return client
Example #11
0
#
#
#url = 'https://www.douban.com/service/auth2/auth?'
#url = url + client_id + redirect_uri + scope + response_type
#
#print url,'\n'
#
##webbrowser.open(url,2)
#
#post = '&' + urllib.urlencode(secret)
#
#turl = 'https://www.douban.com/service/auth2/token?'
#post =  client_id + redirect_uri + grant_type + post
#
#print turl
#print post
#
#f = urllib2.urlopen(turl,post)
#print f.readlines()

key = '09b8939a3413aad21d29bace9c3b0076' 
secret = '9859991d44544cb1'
redirect = 'http://bearzk.wordpress.com/'
token = '80dce6eac862de188296b4c059289a48'

client = DoubanClient(key,secret,redirect)
client.auth_with_token(token)

g = client.book.getter()
print g
Example #12
0
from douban_client import DoubanClient

KEY = ''
SECRET = ''
CALLBACK = ''
TOKEN = 'your token'

SCOPE = 'douban_basic_common,community_basic_user'
client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

client.auth_with_token(TOKEN)
print client.user.me