[pinterest] scrap OAuth implementation; code improvements

OAuth authentication isn't needed anymore and other tools
like Postman are better suited for this job anyway.
This commit is contained in:
Mike Fährmann
2018-04-25 16:04:30 +02:00
parent 55d4d23860
commit 0f1e07f627
3 changed files with 7 additions and 66 deletions

View File

@@ -820,35 +820,6 @@ How To
=========== =====
extractor.pinterest.access-token
--------------------------------
=========== =====
Type ``string``
How To - register a Pinterest application and use its client-id and
client-secret (see `extractor.pinterest.client-id & .secret`_)
- run `gallery-dl oauth:pinterest` and authenticate access with
(preferably) the same account that registered the application
Notes Access tokens currently only allow for 10 requests per hour.
=========== =====
extractor.pinterest.client-id & .secret
---------------------------------------
=========== =====
Type ``string``
How To - login and visit Pinterest's
`Apps <https://developers.pinterest.com/apps/>`__ section
- agree to "Pinterest Developer Terms and the API Policy"
and click "Create app"
- choose a random name and description and click "Create"
- scroll down and set a Site URL (e.g. https://example.org/)
and allow https://mikf.github.io/gallery-dl/oauth-redirect.html
as Redirect URI
- scroll back up again, copy the "App ID" and "App secret" values
and put them in your configuration file
=========== =====
extractor.reddit.client-id & .user-agent
----------------------------------------
=========== =====

View File

@@ -198,29 +198,6 @@ class OAuthFlickr(OAuthBase):
)
class OAuthPinterest(OAuthBase):
subcategory = "pinterest"
pattern = ["oauth:pinterest$"]
redirect_uri = "https://mikf.github.io/gallery-dl/oauth-redirect.html"
def items(self):
yield Message.Version, 1
client_id = self.oauth_config("client-id")
client_secret = self.oauth_config("client-secret")
if not client_id or not client_secret:
self.log.error("'client-id' and 'client-secret' required")
return
self._oauth2_authorization_code_grant(
client_id, client_secret,
"https://api.pinterest.com/oauth/",
"https://api.pinterest.com/v1/oauth/token",
scope="read_public", key="access_token", auth=False,
)
class OAuthReddit(OAuthBase):
subcategory = "reddit"
pattern = ["oauth:reddit$"]

View File

@@ -81,15 +81,12 @@ class PinterestBoardExtractor(PinterestExtractor):
def items(self):
board = self.api.board(self.user, self.board)
data = {"board": board, "count": board["pin_count"]}
num = data["count"]
yield Message.Version, 1
yield Message.Directory, data
for pin in self.api.board_pins(board["id"]):
url, pdata = self.data_from_pin(pin)
data.update(pdata)
data["num"] = num
num -= 1
yield Message.Url, url, data
url, pin_data = self.data_from_pin(pin)
pin_data.update(data)
yield Message.Url, url, pin_data
class PinterestPinitExtractor(PinterestExtractor):
@@ -157,11 +154,8 @@ class PinterestAPI():
return self._pagination("BoardFeed", options)
def _call(self, resource, options):
url = "{}/resource/{}Resource/get".format(self.BASE_URL, resource)
params = {
"source_url": "",
"data": json.dumps({"options": options}),
}
url = "{}/resource/{}Resource/get/".format(self.BASE_URL, resource)
params = {"data": json.dumps({"options": options}), "source_url": ""}
response = self.session.get(url, params=params, headers=self.HEADERS)
data = response.json()
@@ -179,10 +173,8 @@ class PinterestAPI():
self.log.error("API request failed: %s", msg)
raise exception.StopExtraction()
def _pagination(self, resource, options, bookmarks=None):
def _pagination(self, resource, options):
while True:
if bookmarks:
options["bookmarks"] = bookmarks
data = self._call(resource, options)
yield from data["resource_response"]["data"]
@@ -190,5 +182,6 @@ class PinterestAPI():
bookmarks = data["resource"]["options"]["bookmarks"]
if not bookmarks or bookmarks[0] == "-end-":
return
options["bookmarks"] = bookmarks
except KeyError:
return