def get_douban_client(app_config): scope = 'douban_basic_common,movie_basic_r,movie_advance_r' client = DoubanClient( app_config['douban_app_key'], app_config['douban_app_secret'], app_config['douban_redirect_url'], scope) return client
def get(self,code): douban = DoubanClient(API_KEY, SECRET, 'http://book.douban.com',SCOPE) douban.auth_with_code(code) token = douban.access_token.token print token duser = douban.user.me print duser user = connection.User() user['id']=int(duser['uid']) user['password'] = token user.save() return token
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
def new(): client = DoubanClient(API_KEY, API_SECRET, CALLBACK, SCOPE) code = request.form.get('code') image = request.files.get('image') comment = request.form.get('comment', '') hash1 = request.form.get('hash[new1]', '') hash2 = request.form.get('hash[new2]', '') hash3 = request.form.get('hash[new3]', '') if image: fname = '/tmp/1.jpg' image.save(fname) hash_text = hash_name([hash1, hash2, hash3]) text = "%s %s" % (comment, hash_text) text = text.encode("utf-8") #try: client.auth_with_code(code) client.miniblog.new(text, image=open(fname)) #except DoubanError: # return redirect('/login') return "Upload OK" else: return "Error"
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
from douban_client import DoubanClient from util import mongocli import json API_KEY = '0d0690ea685259262713b2bf38f70b72' API_SECRET = 'bf6e552666db43a0' SCOPE = 'douban_basic_common,community_basic_user' client = DoubanClient(API_KEY, API_SECRET, 'http://localhost:5000', SCOPE) def get_douban_eventlist(date): #find solidify event solidify_event = mongocli.find_douban_eventlist(date) if solidify_event is None: event = client.event.list(108296, 'day', 'all', date, 15) mongocli.save_douban_eventlist({"date": date, "event": event}) return event else: return solidify_event
# -*- coding:utf-8 -*- from douban_client import DoubanClient API_KEY = '020a9c5869bcf26b061fd5093d36d741' API_SECRET = '2e6e4d4785a8c438' REDIRECT_URI = 'http://freesz.sinaapp.com/douban' # 在 OAuth 2.0 中, # 获取权限需要指定相应的 scope,请注意!! # scope 权限可以在申请应用的 "API 权限" 查看。 SCOPE = 'douban_basic_common,book_basic_r,book_basic_w' client = DoubanClient(API_KEY, API_SECRET, REDIRECT_URI, SCOPE) print client.authorize_url
from six.moves import input from douban_client import DoubanClient KEY = '' SECRET = '' CALLBACK = '' SCOPE = 'douban_basic_common,community_basic_user' client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE) print client.authorize_url code = input('Enter the verification code:') client.auth_with_code(code) print client.user.me
# coding: utf-8 """ 使用 hist magic 保存 ipython 命令, 便于命令行调试 %hist """ import time from datetime import datetime from douban_client import DoubanClient from douban_mongo import StorageClient import logging log = logging.getLogger(__name__) level = logging.WARNING level = logging.DEBUG logging.basicConfig(format='%(name)s \t\t%(levelname)-8s %(filename)8s %(funcName)8s() [%(message)-60s] %(module)s', level=level) douban_client = DoubanClient() mongo_client = StorageClient() content, error = douban_client.movie_in_theaters() type(content) print("将这些代码复制到 ipython 中,便于调试 ..")
def __init__(self): self.clent = DoubanClient(KEY, SECRET, CALLBACK, SCOPE) self.clent.auth_with_token(TOKEN)
#!/usr/bin/env python # encoding: utf-8 from douban_client import DoubanClient from ruamel import yaml import logging import threading API_KEY = '' API_SECRET = '' SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w,book_basic_r' client = DoubanClient(API_KEY, API_SECRET, '', SCOPE) client.auth_with_password('', '') logger = logging.getLogger(__file__) con = threading.Condition() sdk_count = 0 def getClient(): return client def getBookByIsbn(isbn): return client.book.isbn(isbn) def getBookById(id): logger
# -*- coding:utf-8 -*- from douban_client import DoubanClient from xsettings import XCFG API_KEY = XCFG.WECHAT_API_KEY API_SECRET = XCFG.WECHAT_API_SECRET REDIRECT_URI = XCFG.WECHAT_REDIRECT_URI SCOPE = XCFG.WECHAT_SCOPE client_wechat = DoubanClient(API_KEY, API_SECRET, REDIRECT_URI, SCOPE) LOGIN_API_KEY = XCFG.LOGIN_API_KEY LOGIN_API_SECRET = XCFG.LOGIN_API_SECRET LOGIN_REDIRECT_URI = XCFG.LOGIN_REDIRECT_URI LOGIN_SCOPE = XCFG.LOGIN_SCOPE client_login = DoubanClient(LOGIN_API_KEY, LOGIN_API_SECRET, LOGIN_REDIRECT_URI, LOGIN_SCOPE)
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
when you run "manage.py test". Replace this with more appropriate tests for your application. """ from django.test import TestCase class SimpleTest(TestCase): def test_basic_addition(self): """ Tests that 1 + 1 always equals 2. """ self.assertEqual(1 + 1, 2) if __name__ == "__main__": from douban_client import DoubanClient API_KEY = '074b071d3b024f8315e11557b106ee89' API_SECRET = '35e9df8c4c8a7435' SCOPE = 'shuo_basic_r,shuo_basic_w' your_redirect_uri = 'http://hobo.sinaapp.com/' client = DoubanClient(API_KEY, API_SECRET, your_redirect_uri, SCOPE) print 'Go to the following link in your browser:' print client.authorize_url code = raw_input('Enter the verification code:') client.auth_with_code(code)
#encoding:utf-8 from douban_client import DoubanClient from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth import authenticate, login as auth_login from django.contrib.auth.models import User from models import UserProfile from models import Link from accounts.signals import new_user_register import settings API_KEY = settings.DOUBAN_API_KEY API_SECRET = settings.DOUBAN_API_SECRET SCOPE = settings.DOUBAN_SCOPE CALLBACK_URL = settings.DOUBAN_CALLBACK_URL client = DoubanClient(API_KEY, API_SECRET, CALLBACK_URL) def index(request): """ 跳转到验证页面 """ auth_url = client.authorize_url return HttpResponseRedirect(auth_url) def callback(request): """ 用户授权后的回调 """ code = request.GET.get(u'code')
def autopraise(id0): #需要申请一个豆瓣API KEY, 在这里申请 http://developers.douban.com/apikey/apply API_KEY = '' API_SECRET = '' # 在 OAuth 2.0 中, # 获取权限需要指定相应的 scope,请注意!! SCOPE = 'shuo_basic_r,shuo_basic_w,miniblog_basic_r,miniblog_basic_w' callback = "http://www.XXXX.com/callback" #填你申请时候的回调地址,有没有网站都无所谓 client = DoubanClient(API_KEY, API_SECRET, callback, SCOPE) # 存储授权地址 authurl = client.authorize_url # print authurl f = open("c:/authurl.txt", "w") # # 读取页面源代码 br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) br.set_handle_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) #模拟浏览器行为 br.addheaders = [( 'User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0' )] r2 = br.open(authurl) br.select_form(nr=1) br['user_email'] = '' #你的豆瓣用户名和密码 br['user_passwd'] = '' r3 = br.submit() c = r3.geturl() f.write(c) #从请求页面回调地址中查找code m = re.findall("(?<=code\=).*", c) code = m[0] print code # 用code授权client client.auth_with_code(code) #获取最近广播数据 r4 = br.open("http://api.douban.com/shuo/v2/statuses/home_timeline?count=5" ) #Count这里可以修改获取的广播数量,5比较多 caststr = r4.read() id1 = re.findall("(?<=id\"\:)\d+", caststr) #友邻白名单 def whitelist(): r1 = br.open( "http://api.douban.com/shuo/v2/statuses/user_timeline/XXXX" ) #XXXX处 填写你不想赞的友邻用户名 cast1 = r1.read() id1 = re.findall("(?<=id\"\:)\d+", cast1) id = id1 return id f.write(caststr) #存储广播列表 for id in id1: if id in id0: break if id in whitelist(): break client.miniblog.like(id) #赞 print "liked" if hour > 2 and hour < 7: client.miniblog.comment.new(id, "Yo,watch body young man") #提醒友邻睡觉啦 pass return id1
from douban_client import DoubanClient import memcache DOUBAN_API_KEY = '0beb137ce048a99623c13a76a0d9fcc2' DOUBAN_API_SECRET = '0c4e47816f6a0a93' DOUBAN_SCOPE = 'book_basic_r,book_basic_w,community_basic_note,community_basic_online,community_basic_photo,community_advanced_photo,community_basic_user,douban_basic_common,event_basic_r,event_basic_w,movie_basic_r,movie_basic_w,music_artist_r,music_basic_r,music_basic_w,shuo_basic_r,shuo_basic_w' DOUBAN_REDIRECT_URI = 'http://book.douban.com:8080/login' client = DoubanClient(DOUBAN_API_KEY, DOUBAN_API_SECRET, DOUBAN_REDIRECT_URI, DOUBAN_SCOPE) mc = memcache.Client(['127.0.0.1:12000'], debug=True)
def login(): client = DoubanClient(API_KEY, API_SECRET, CALLBACK, SCOPE) auth_url = client.authorize_url return st('login.html', **locals())