Created
April 7, 2026 11:15
-
-
Save danyaljj/67a026546c3bb68031bfd344a7e75027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| PAPER_ID = "0a2c5dfa8b273c0130a0b59be7ce5dba575303be" | |
| BASE_URL = "https://api.semanticscholar.org/graph/v1" | |
| S2_API_KEY = "..." | |
| HEADERS = {"x-api-key": S2_API_KEY} | |
| PAPER_FIELDS = "title,abstract,year,authors,citationCount,referenceCount,externalIds,venue,publicationDate" | |
| REF_FIELDS = "title,authors,year,citationCount,externalIds" | |
| def fetch_paper_details(paper_id): | |
| url = f"{BASE_URL}/paper/{paper_id}" | |
| resp = requests.get(url, params={"fields": PAPER_FIELDS}, headers=HEADERS) | |
| resp.raise_for_status() | |
| return resp.json() | |
| def fetch_references(paper_id, limit=100): | |
| url = f"{BASE_URL}/paper/{paper_id}/references" | |
| params = {"fields": REF_FIELDS, "limit": limit} | |
| resp = requests.get(url, params=params, headers=HEADERS) | |
| resp.raise_for_status() | |
| return resp.json() | |
| if __name__ == "__main__": | |
| print("=== Paper Details ===") | |
| details = fetch_paper_details(PAPER_ID) | |
| print(f"Title: {details.get('title')}") | |
| print(f"Year: {details.get('year')}") | |
| print(f"Venue: {details.get('venue')}") | |
| print(f"Authors: {', '.join(a['name'] for a in details.get('authors', []))}") | |
| print(f"Citations: {details.get('citationCount')}") | |
| print(f"References: {details.get('referenceCount')}") | |
| print(f"Abstract: {details.get('abstract', '')[:300]}...") | |
| print("\n=== References ===") | |
| refs = fetch_references(PAPER_ID) | |
| data = refs.get("data") | |
| if not data: | |
| print("No references returned. Raw response:") | |
| print(refs) | |
| else: | |
| for i, item in enumerate(data, 1): | |
| ref = item.get("citedPaper", {}) | |
| authors = ", ".join(a["name"] for a in ref.get("authors", [])[:3]) | |
| print(f"{i:3}. {ref.get('title', 'N/A')} ({ref.get('year', '?')}) — {authors}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment