Editorial Workflows

Pocket Authentication

unlisted workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: This workflow has no description.

Shared by: @hals_pg

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# -*- coding: utf-8 -*-
import sys
import keychain
import requests
from urllib import urlencode
import webbrowser
import keychain


sys.setdefaultencoding('utf-8')

consumer_key = raw_input('Consumer keyを入力してください: ')
redirect_uri = 'editorial://'

headers = {
	'X-Accept': 'application/json'
}

params = {
	'consumer_key' : consumer_key,
	'redirect_uri' : redirect_uri
}

r = requests.post(
	'https://getpocket.com/v3/oauth/request',
	headers=headers,
	data=params
)

request_token = r.json()['code']

params = {
	'request_token' : request_token,
	'redirect_uri' : redirect_uri
}

webbrowser.open(
	'https://getpocket.com/auth/authorize?' + urlencode(params)
)
wait_response = raw_input(
	'認証が完了したら何も入力せずにEnterをタップ'
)

if wait_response == '':

	params = {
		'consumer_key' : consumer_key,
		'code' : request_token }

	r = requests.post(
		'https://getpocket.com/v3/oauth/authorize',
		headers=headers,
		data=params
	)

	access_token = r.json()['access_token']

	keychain.set_password(
		'pocket_utility',
		'keys',
		'{}|{}'.format(
			consumer_key, access_token
		)
	)
	print '\n認証が完了しました。\n'
	print 'Consumer key: {}'.format(consumer_key)
	print 'Access token: {}'.format(access_token)
	print '\nKeychainに保存されているのでご利用ください。'
	print "keychain.get_password('pocket_utility', 'keys')"