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
Пример #3
0
#!/usr/bin/env python3
from douban_client import DoubanClient

API_KEY = '0c39dde0317db0f024ad99a0947912d0'
API_SEC = 'e30f500ed75a3a4f'
REDIRECT_URL = 'http://blog.unionx.me/callback'

SCOPE = 'book_basic_r, book_basic_w, shuo_basic_r, douban_basic_common'

client = DoubanClient(API_KEY, API_SEC, REDIRECT_URL, SCOPE)

print('Go to the following link in your browser:')
print(client.authorize_url)
code = input('Enter the verification code:\n')
client.auth_with_code(code)

# 2. 如果有之前有 token,则可以
# client.auth_with_token(token)

# Token Code
token_code = client.token_code
print(token_code)

book = client.book.get(26372794)
print(book)

# Refresh Token
# 请注意:`refresh_token_code` 值仅可在授权完成时获取(即在 `auth_with_code`, `auth_with_password` 之后)
refresh_token_code = client.refresh_token_code
client.refresh_token(refresh_token_code) # refresh token
Пример #4
0
from douban_client import DoubanClient

API_KEY = '0e5eae024adb9ce12b1c0a06e092d6a3'
API_SECRET = '9f7ef068498fc361'

# 在 OAuth 2.0 中,
# 获取权限需要指定相应的 scope,请注意!!
# scope 权限可以在申请应用的 "API 权限" 查看。

SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w'

client = DoubanClient(API_KEY, API_SECRET, "http://opac.whsw.tk", SCOPE)

# 以下方式 2 选 1:
# 1. 引导用户授权
print('Go to the following link in your browser:')
print(client.authorize_url)
code = input('Enter the verification code:')
client.auth_with_code(code)

# 2. 如果有之前有 token,则可以
#client.auth_with_token(token)

# Token Code
token_code = client.token_code

# Refresh Token
# 请注意:`refresh_token_code` 值仅可在授权完成时获取(即在 `auth_with_code`, `auth_with_password` 之后)
refresh_token_code = client.refresh_token_code
client.refresh_token(refresh_token_code)  # refresh token