如何导出带标签的Pocket文章列表?含Python API使用场景
Using the Official Pocket API
The Pocket API absolutely supports fetching your custom tags—you just need to adjust your request parameters to include full item metadata. Here's how to implement this in Python:
Step 1: Confirm Authentication Setup
First, make sure you have a valid access token from Pocket's OAuth flow. You'll need to register an app on Pocket's developer platform, then complete the authorization process to get your consumer key and access token.
Step 2: Fetch Articles with Tags Included
When calling the /v3/get endpoint, set the detailType parameter to complete—this triggers the API to return all metadata, including your custom tags for each article. Here's a working Python snippet using the requests library:
import requests POCKET_API_ENDPOINT = "https://getpocket.com/v3/get" request_headers = { "Content-Type": "application/json", "X-Accept": "application/json" } request_payload = { "consumer_key": "YOUR_CONSUMER_KEY", "access_token": "YOUR_ACCESS_TOKEN", "detailType": "complete", # Required to pull tag data "state": "all" # Retrieve every article, not just unread ones } response = requests.post(POCKET_API_ENDPOINT, json=request_payload) articles = response.json() # Extract and display articles with their tags for item_id, article in articles["list"].items(): article_title = article.get("resolved_title", article.get("given_title", "Untitled")) tag_dict = article.get("tags", {}) tag_list = list(tag_dict.keys()) if tag_dict else [] print(f"Title: {article_title}\nTags: {tag_list}\n---")
Each article's tags field comes as a dictionary where keys are your custom tag names—converting this to a list makes it easier to work with.
Alternative Non-API Method: Direct Export from Pocket
If you'd rather skip API setup, Pocket lets you export your entire library (tags included) directly from your web account:
- Log into Pocket on the web and click your profile icon in the top-right corner.
- Select Settings from the dropdown menu.
- Scroll to the Export section near the bottom of the page.
- Choose the JSON export format (it’s the most straightforward to parse programmatically, as it includes a
tagsarray for each item). - Download the file, then load and process it in Python like this:
import json with open("pocket-export.json", "r") as export_file: export_data = json.load(export_file) for article in export_data["list"]: article_title = article.get("resolved_title", article.get("given_title", "Untitled")) tag_list = article.get("tags", []) print(f"Title: {article_title}\nTags: {tag_list}\n---")
Quick Troubleshooting Tips
- If tags are missing from API responses, double-check that
detailTypeis set tocomplete(notsimpleorbasic). - Ensure your access token has the default read permissions—these include access to tag data by default.
- For the export method, avoid using the HTML format unless you want to manually parse tags; JSON is far more reliable for automated processing.
内容的提问来源于stack exchange,提问作者Toro

