本文整理汇总了Python中pocket.Pocket.get_access_token方法的典型用法代码示例。如果您正苦于以下问题:Python Pocket.get_access_token方法的具体用法?Python Pocket.get_access_token怎么用?Python Pocket.get_access_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocket.Pocket
的用法示例。
在下文中一共展示了Pocket.get_access_token方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pocket_authorized
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def pocket_authorized():
access_token = Pocket.get_access_token(consumer_key=POCKET_APP_TOKEN,
code=session['request_token'])
resp = {'oauth_token': access_token, 'oauth_secret': ''}
creation_or_link, redirect = process_authorized('pocket', resp,
lambda x: True, 'oauth_token', 'oauth_token_secret')
return redirect
示例2: get_client
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def get_client(self):
"""
Connects to Pocket API using OAuth
"""
request_token = pckt.get_request_token(
consumer_key=self.consumer_key,
redirect_uri=self.REDIRECT_URI
)
log.debug(request_token)
# URL to redirect user to, to authorize your app
auth_url = pckt.get_auth_url(
code=request_token,
redirect_uri=self.REDIRECT_URI
)
log.debug(auth_url)
# only needed to authorize your app the first time
#request_token2 = input('request token: ')
if not self.access_token:
self.access_token = pckt.get_access_token(
consumer_key=self.consumer_key, code=request_token)
log.debug(self.access_token)
return pckt(
consumer_key=self.consumer_key,
access_token=self.access_token)
示例3: callback
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def callback(self, request):
"""
Called from the Service when the user accept to activate it
"""
try:
# finally we save the user auth token
# As we already stored the object ServicesActivated
# from the UserServiceCreateView now we update the same
# object to the database so :
# 1) we get the previous object
us = UserService.objects.get(
user=request.user,
name=ServicesActivated.objects.get(name='ServicePocket'))
# 2) then get the token
access_token = Pocket.get_access_token(
consumer_key=self.consumer_key,
code=request.session['request_token'])
us.token = access_token
# 3) and save everything
us.save()
except KeyError:
return '/'
return 'pocket/callback.html'
示例4: callback
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def callback(self, request, **kwargs):
"""
Called from the Service when the user accept to activate it
:param request: request object
:return: callback url
:rtype: string , path to the template
"""
access_token = Pocket.get_access_token(consumer_key=self.consumer_key, code=request.session['request_token'])
kwargs = {'access_token': access_token}
return super(ServicePocket, self).callback(request, **kwargs)
示例5: callback
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def callback(self, request, **kwargs):
"""
Called from the Service when the user accept to activate it
"""
access_token = Pocket.get_access_token(
consumer_key=self.consumer_key,
code=request.session['request_token'])
kwargs = {'access_token': access_token, 'service': 'ServicePocket',
'return': 'pocket'}
return super(ServicePocket, self).callback(request, **kwargs)
示例6: pocket_success
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def pocket_success(request):
try:
access_token = Pocket.get_access_token(
consumer_key=settings.POCKET_CONSUMER_KEY,
code=request.user.profile.pocket_request_token
)
except Exception as e:
print(e)
return HttpResponse(e)
request.user.profile.pocket_access_token = access_token
request.user.profile.save()
messages.add_message(request, messages.SUCCESS,
'Successfully connected to Pocket.')
return HttpResponseRedirect(reverse('feeds_index'))
示例7: auth_callback
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def auth_callback():
pocket = Pocket(config.POCKET_CONSUMER_KEY)
code = session['code']
try:
resp = pocket.get_access_token(code)
session.pop('access_token', None)
username = resp['username']
token = resp['access_token']
session['access_token'] = token
session['username'] = username
model.User.insert(name = username, token = token).upsert().execute()
# add async task
sync.pool.add_task(sync.sync_all_for_user, username, token)
except APIError as apie:
return str(apie)
return session['username'] + " " + session['access_token']
示例8: main
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def main():
creds = client.OAuth2Credentials(
config.YOUTUBE_ACCESS_TOKEN, config.YOUTUBE_CLIENT_ID,
config.YOUTUBE_CLIENT_SECRET, config.YOUTUBE_REFRESH_TOKEN,
arrow.get(config.YOUTUBE_TOKEN_EXPIRY),
config.YOUTUBE_TOKEN_URI, config.YOUTUBE_USER_AGENT)
if creds.token_expiry <= arrow.get():
creds.refresh(Http())
config.YOUTUBE_ACCESS_TOKEN = creds.access_token
config.YOUTUBE_TOKEN_EXPIRY = creds.token_expiry.isoformat()
config.save()
http = authorized_http(creds)
youtube = build('youtube', 'v3', http=http())
if not config.POCKET_ACCESS_TOKEN:
import webbrowser
request_token = Pocket.get_request_token(config.POCKET_CONSUMER_KEY)
auth_url = Pocket.get_auth_url(request_token)
webbrowser.open(auth_url)
raw_input('Press ENTER when done ')
access_token = Pocket.get_access_token(config.POCKET_CONSUMER_KEY,
request_token)
config.POCKET_ACCESS_TOKEN = access_token
config.save()
pocket = Pocket(config.POCKET_CONSUMER_KEY, config.POCKET_ACCESS_TOKEN)
playlists = youtube.playlists().list(part='snippet', mine=True).execute()
favorites = next((item for item in playlists['items']
if item['snippet']['title'] == 'Favorites'), None)
req = youtube.playlistItems().list(part='snippet',
playlistId=favorites['id'])
pool = Pool()
while req:
res = req.execute()
for item in res['items']:
pool.spawn(put_in_pocket, youtube, http, pocket, item)
req = youtube.playlistItems().list_next(req, res)
pool.join()
示例9: handle_data
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
def handle_data(self, data):
if self.readData:
print "Tag: ", data
currentTag = data
self.readData = False
request_token = Pocket.get_request_token(consumer_key, redirect_uri)
auth_url = Pocket.get_auth_url(request_token,redirect_uri)
webbrowser.open_new_tab(auth_url)
print 'Please authorize the app using the following url and press ENTER here', auth_url
raw_input()
access_token = Pocket.get_access_token(consumer_key=consumer_key, code=request_token)
print 'Got request token', request_token
print 'Got access token', access_token
def add_url(url, tag):
print 'adding', url
pocket_instance = Pocket(consumer_key, access_token)
print pocket_instance.add(url=url, tags=[tag])
file = open(filename, 'r')
content = file.read()
file.close()
parser = MyHTMLParser()
示例10: __init__
# 需要导入模块: from pocket import Pocket [as 别名]
# 或者: from pocket.Pocket import get_access_token [as 别名]
class PocketApp:
DEFAULT_WORDS_PER_MINUTE = 180
REDIRECT_URL = 'http://www.google.com'
def __init__(self):
self._configs = Configs()
self._storage = Storage()
self._pocket = Pocket(
self._configs.get('consumer_key'),
self._configs.get('access_token')
)
def configure(self, consumer_key, access_token,
words_per_minute, sort_field):
self._configs.set('consumer_key', consumer_key)
self._configs.set('access_token', access_token)
self._configs.set('words_per_minute', words_per_minute)
self._configs.set('sort_field', sort_field)
self._configs.set('last_fetch', 0)
self._configs.write()
self._storage.clear()
def get_request_token(self, consumer_key):
return self._pocket.get_request_token(
consumer_key, self.REDIRECT_URL
)
def get_access_token(self, consumer_key, request_token):
return self._pocket.get_access_token(
consumer_key, request_token
)
def add_article(self, url, title=None, tags=None):
if isinstance(tags, tuple):
tags = ','.join(list(tags))
try:
return self._pocket.add(url, title, tags)
except PocketException as e:
raise_from(self._check_exception(e), e)
def get_articles(self, limit=None, order=None):
if self._storage.is_empty():
self.fetch_articles(True)
articles = self._storage.read(limit, order)
sort_field = self._configs.get('sort_field')
if not sort_field:
sort_field = 'reading_time'
articles = sorted(articles,
key=itemgetter(sort_field))
return articles
def search(self, search, state, tag, sort):
try:
articles = self._pocket.retrieve(search=search,
state=state,
tag=tag,
sort=sort)
return self._get_articles_index(articles)
except PocketException as e:
raise_from(self._check_exception(e), e)
def archive_article(self, item_id):
try:
self._pocket.archive(int(item_id)).commit()
except PocketException as e:
raise_from(self._check_exception(e), e)
def find_article(self, item_id):
index = self._storage.read()
for article in index:
if str(article['id']) == str(item_id):
return article
return None
def fetch_articles(self, output_progress=False):
spinner = None
if output_progress:
spinner = Spinner('Loading articles ')
articles_index = []
last_fetch = self._configs.get('last_fetch')
offset = 0
count = 20
while(True):
try:
articles = self._pocket.retrieve(
state='unread',
count=count,
offset=offset,
since=last_fetch
)
#.........这里部分代码省略.........