The GoogleScholarSwift
package provides an easy-to-use interface for fetching publication data from Google Scholar. It allows users to retrieve detailed information about an author's publications, including titles, publication years, links, and citation counts. This package is designed for academics, researchers, and anyone interested in programmatically analyzing scholarly publication data.
To integrate GoogleScholarSwift
into your Xcode project using Swift Package Manager, add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/ezefranca/GoogleScholarSwift.git", from: "1.2.0")
]
Then add GoogleScholarSwift
as a dependency in your target:
.target(
name: "YourTargetName",
dependencies: [
.product(name: "GoogleScholarSwift", package: "GoogleScholarSwift")
]
)
Fetches all publications for a given author from Google Scholar.
public func fetchAllPublications(
authorID: GoogleScholarID,
fetchQuantity: FetchQuantity = .all,
sortBy: SortBy = .cited
) async throws -> [Publication]
authorID
: The Google Scholar author ID.fetchQuantity
: The quantity of publications to fetch. Can be.all
or.specific(Int)
. Default is.all
.sortBy
: The sorting criterion for publications. Can be.cited
or.pubdate
. Default is.cited
.
- An array of
Publication
objects.
- An error if fetching or parsing fails.
let fetcher = GoogleScholarFetcher()
// Fetch all publications for a given author ID
let publications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"))
print(publications)
// Fetch a specific number of publications for a given author ID
let limitedPublications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"), fetchQuantity: .specific(10))
print(limitedPublications)
// Fetch all publications for a given author ID and sort by pubdate
let sortedPublications = try await fetcher.fetchAllPublications(authorID: GoogleScholarID("RefX_60AAAAJ"), sortBy: .pubdate)
print(sortedPublications)
Fetches the detailed information for a specific article.
public func fetchArticle(articleLink: ArticleLink) async throws -> Article
articleLink
: AnArticleLink
object containing the link to the article.
- An
Article
object.
- An error if fetching or parsing fails.
let fetcher = GoogleScholarFetcher()
let articleLink = ArticleLink(link: "https://scholar.google.com/citations?view_op=view_citation&hl=en&user=RefX_60AAAAJ&citation_for_view=RefX_60AAAAJ:9yKSN-GCB0IC")
let article = try await fetcher.fetchArticle(articleLink: articleLink)
print(article)
Fetches the Author's details such as name, affiliation, and picture URL from Google Scholar.
public func fetchAuthorDetails(scholarID: GoogleScholarID) async throws -> Author
scholarID
: The Google Scholar author ID.
- A
Author
object containing the Author's details.
- An error if fetching or parsing fails.
let fetcher = GoogleScholarFetcher()
let AuthorDetails = try await fetcher.fetchAuthorDetails(scholarID: GoogleScholarID("6nOPl94AAAAJ"))
print(AuthorDetails)
import GoogleScholarSwift
let fetcher = GoogleScholarFetcher()
let authorID = GoogleScholarID("RefX_60AAAAJ")
// Fetch all publications for a given author ID
let publications = try await fetcher.fetchAllPublications(authorID: authorID)
print("All Publications:", publications)
// Fetch a specific number of publications for a given author ID
let limitedPublications = try await fetcher.fetchAllPublications(authorID: authorID, fetchQuantity: .specific(10))
print("Limited Publications:", limitedPublications)
// Fetch all publications for a given author ID and sort by pubdate
let sortedPublications = try await fetcher.fetchAllPublications(authorID: authorID, sortBy: .pubdate)
print("Sorted Publications:", sortedPublications)
// Fetch article details for the first publication
if let firstPublication = publications.first {
let articleLink = ArticleLink(link: firstPublication.link)
let article = try await fetcher.fetchArticle(articleLink: articleLink)
print("Article Details:", article)
}
// Fetch Author details
let AuthorDetails = try await fetcher.fetchAuthorDetails(scholarID: authorID)
print("Author Details:", AuthorDetails)
We welcome contributions to GoogleScholarSwift
! If you have suggestions for improvements, please open an issue or a pull request.
This project is not affiliated with Google and is intended for educational purposes only. The responsibility for the use and interpretation of the data obtained through this project lies solely with the user. The developers and contributors of this project are not liable for any misuse or legal implications arising from the utilization of the data provided. Users are advised to ensure compliance with applicable laws and regulations when using this project.
GoogleScholarSwift
is released under the MIT License. See the LICENSE file for more details.