allow users to set their own API access_tokens/client_ids

pull/40/head
Mike Fährmann 7 years ago
parent 49c7e70c10
commit 54c0715135
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -9,7 +9,7 @@ Contents
3) `Downloader Options`_
4) `Extractor Options`_
5) `Extractor-specific Options`_
6) `API Tokens & IDs`_
General Options
===============
@ -551,6 +551,49 @@ Description The ``refresh_token`` value you get from linking your Reddit account
=========== =====
API Tokens & IDs
================
extractor.deviantart.client-id & .client-secret
-----------------------------------------------
=========== =====
Type ``string``
Description
=========== =====
extractor.flickr.api-key & .api-secret
--------------------------------------
=========== =====
Type ``string``
Description
=========== =====
extractor.pawoo.access-token
----------------------------
=========== =====
Type ``string``
Description
=========== =====
extractor.pinterest.access-token
--------------------------------
=========== =====
Type ``string``
Description
=========== =====
extractor.reddit.client-id
--------------------------
=========== =====
Type ``string``
Description
=========== =====
.. |.netrc| replace:: ``.netrc``
.. |tempfile.gettempdir()| replace:: ``tempfile.gettempdir()``
.. |requests.request()| replace:: ``requests.request()``

@ -334,8 +334,8 @@ class DeviantartAPI():
client_secret="76b08c69cfb27f26d6161f9ab6d061a1"):
self.session = extractor.session
self.log = extractor.log
self.client_id = client_id
self.client_secret = client_secret
self.client_id = extractor.config("client-id", client_id)
self.client_secret = extractor.config("client-secret", client_secret)
self.delay = 0
self.mature = extractor.config("mature", "true")
if not isinstance(self.mature, str):

@ -256,13 +256,15 @@ class FlickrAPI():
]
def __init__(self, extractor):
self.api_key = extractor.config("api-key", self.API_KEY)
self.api_secret = extractor.config("api-secret", self.API_SECRET)
token = extractor.config("access-token")
token_secret = extractor.config("access-token-secret")
if token and token_secret:
self.session = util.OAuthSession(
extractor.session,
self.API_KEY, self.API_SECRET, token, token_secret)
self.API_KEY = None
self.api_key, self.api_secret, token, token_secret)
self.api_key = None
else:
self.session = extractor.session
@ -365,8 +367,8 @@ class FlickrAPI():
params["method"] = "flickr." + method
params["format"] = "json"
params["nojsoncallback"] = "1"
if self.API_KEY:
params["api_key"] = self.API_KEY
if self.api_key:
params["api_key"] = self.api_key
data = self.session.get(self.API_URL, params=params).json()
if "code" in data and data["code"] == 1:
raise exception.NotFoundError(self.subcategory)

@ -20,7 +20,7 @@ class PawooExtractor(Extractor):
def __init__(self):
Extractor.__init__(self)
self.api = MastodonAPI(self.session, self.log)
self.api = MastodonAPI(self)
def items(self):
yield Message.Version, 1
@ -108,12 +108,12 @@ class MastodonAPI():
https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md
"""
def __init__(self, session, log, root="https://pawoo.net",
def __init__(self, extractor, root="https://pawoo.net",
access_token=("0f04191976cf22a5319c1e91a73cbcb2"
"510b589e2757efcca922f9b3173d119b")):
self.session = session
access_token = extractor.config("access-token", access_token)
self.session = extractor.session
self.session.headers["Authorization"] = "Bearer " + access_token
self.log = log
self.root = root
def search(self, searchterm):

@ -19,7 +19,7 @@ class PinterestExtractor(Extractor):
def __init__(self):
Extractor.__init__(self)
self.api = PinterestAPI(self.session)
self.api = PinterestAPI(self)
def data_from_pin(self, pin):
"""Get image url and metadata from a pin-object"""
@ -135,9 +135,10 @@ class PinterestPinitExtractor(PinterestExtractor):
class PinterestAPI():
"""Minimal interface for the pinterest API"""
def __init__(self, session, access_token="AV2U9Oe6dyC2vfPugUnBvJ7Duxg9"
"FHCJPXPZIvRDXv9hvwBALwAAAAA"):
self.session = session
def __init__(self, extractor, access_token="AV2U9Oe6dyC2vfPugUnBvJ7Duxg9"
"FHCJPXPZIvRDXv9hvwBALwAAAAA"):
access_token = extractor.config("access-token", access_token)
self.session = extractor.session
self.session.params["access_token"] = access_token
def pin(self, pin_id, fields="id,image,note"):

@ -110,6 +110,7 @@ class RedditAPI():
self.extractor = extractor
self.comments = extractor.config("comments", 500)
self.morecomments = extractor.config("morecomments", False)
self.client_id = extractor.config("client-id", self.CLIENT_ID)
self.refresh_token = extractor.config("refresh-token")
self.log = extractor.log
self.session = extractor.session
@ -165,7 +166,7 @@ class RedditAPI():
data = {"grant_type": ("https://oauth.reddit.com/"
"grants/installed_client"),
"device_id": "DO_NOT_TRACK_THIS_DEVICE"}
response = self.session.post(url, data=data, auth=(self.CLIENT_ID, ""))
response = self.session.post(url, data=data, auth=(self.client_id, ""))
if response.status_code != 200:
raise exception.AuthenticationError()
return "Bearer " + response.json()["access_token"]

Loading…
Cancel
Save