MyNixOS website logo
Description

Access 'The Guardian' Newspaper Open Data API.

Access to 'The Guardian' newspaper's open API <https://open-platform.theguardian.com/>, containing all articles published in 'The Guardian' from 1999 to the present, including article text, metadata, tags and contributor information. An API key and registration is required.

guardianapi

License:MIT CRANstatus GitHubtag AppVeyor buildstatus Travis buildstatus Coveragestatus DOI

Access to the Guardian open API https://open-platform.theguardian.com/, containing all articles published in the Guardian from 1999 to the present. An API key is required, sign up here.

Installation

guardianapi is available on CRAN:

install.packages("guardianapi")

You can install the development version guardianapi from github with:

# install.packages("devtools")
devtools::install_github("evanodell/guardianapi")

Usage

Save your API key as the environmental variable GU_API_KEY, or use the gu_api_key() function to set a key for a single session.

guardianapi contains functions to query and retrieve articles, tags, editions and sections. For example, return all tags containing the string “apple”, which includes both the technology company and Fiona Apple, amongst others.

library(guardianapi)

tags1 <- gu_tags(query = "apple")
#> Retrieving page 1

tibble::glimpse(tags1)
#> Observations: 10
#> Variables: 13
#> $ id               <chr> "technology/apple", "technology/apple-tv", "tec…
#> $ type             <chr> "keyword", "keyword", "keyword", "contributor",…
#> $ section_id       <chr> "technology", "technology", "technology", NA, "…
#> $ section_name     <chr> "Technology", "Technology", "Technology", NA, "…
#> $ web_title        <chr> "Apple", "Apple TV", "Apple WWDC", "Emily Apple…
#> $ web_url          <chr> "https://www.theguardian.com/technology/apple",…
#> $ api_url          <chr> "https://content.guardianapis.com/technology/ap…
#> $ references       <list> [<data.frame[1 x 2]>, <data.frame[0 x 0]>, <da…
#> $ bio              <chr> NA, NA, NA, "<p>Emily Apple is the co-founder o…
#> $ byline_image_url <chr> NA, NA, NA, "https://static.guim.co.uk/sys-imag…
#> $ first_name       <chr> NA, NA, NA, "apple", NA, NA, NA, NA, NA, "chia-…
#> $ last_name        <chr> NA, NA, NA, "emily", NA, NA, NA, NA, NA, "(appl…
#> $ description      <chr> NA, NA, NA, NA, NA, NA, NA, "Guardian journalis…

Return all articles with the string “relationships” and the tag “lifeandstyle/sex” from December 2018:

relations_sex <- gu_content(query = "relationships", from_date = "2018-12-01",
                            to_date = "2018-12-31", tag = "lifeandstyle/sex")
#> Retrieving page 1

tibble::glimpse(relations_sex)
#> Observations: 5
#> Variables: 40
#> $ id                               <chr> "lifeandstyle/2018/dec/10/im-in…
#> $ type                             <chr> "article", "article", "article"…
#> $ section_id                       <chr> "lifeandstyle", "lifeandstyle",…
#> $ section_name                     <chr> "Life and style", "Life and sty…
#> $ web_publication_date             <dttm> 2018-12-10 08:00:39, 2018-12-2…
#> $ web_title                        <chr> "I’m in a relationship with ano…
#> $ web_url                          <chr> "https://www.theguardian.com/li…
#> $ api_url                          <chr> "https://content.guardianapis.c…
#> $ tags                             <list> [<data.frame[10 x 13]>, <data.…
#> $ is_hosted                        <lgl> FALSE, FALSE, FALSE, FALSE, FAL…
#> $ pillar_id                        <chr> "pillar/lifestyle", "pillar/lif…
#> $ pillar_name                      <chr> "Lifestyle", "Lifestyle", "Life…
#> $ headline                         <chr> "I’m in a relationship with ano…
#> $ standfirst                       <chr> "We kiss and cuddle, but he won…
#> $ trail_text                       <chr> "We kiss and cuddle, but he won…
#> $ byline                           <chr> "Pamela Stephenson Connolly", "…
#> $ main                             <chr> "<figure class=\"element elemen…
#> $ body                             <chr> "<p><strong>Until last year, I …
#> $ newspaper_page_number            <chr> "7", "66", "83", NA, "44"
#> $ wordcount                        <chr> "387", "307", "2189", "759", "1…
#> $ comment_close_date               <dttm> 2018-12-13 08:00:39, 2018-12-2…
#> $ commentable                      <chr> "true", "true", "true", "false"…
#> $ first_publication_date           <dttm> 2018-12-10 08:00:39, 2018-12-2…
#> $ is_inappropriate_for_sponsorship <chr> "false", "false", "false", "fal…
#> $ is_premoderated                  <chr> "true", "true", "true", "false"…
#> $ last_modified                    <chr> "2018-12-10T08:00:39Z", "2018-1…
#> $ newspaper_edition_date           <date> 2018-12-10, 2018-12-22, 2018-1…
#> $ production_office                <chr> "UK", "UK", "UK", "UK", "UK"
#> $ publication                      <chr> "The Guardian", "The Guardian",…
#> $ short_url                        <chr> "https://gu.com/p/a5fad", "http…
#> $ should_hide_adverts              <chr> "false", "false", "false", "fal…
#> $ show_in_related_content          <chr> "true", "true", "true", "true",…
#> $ thumbnail                        <chr> "https://media.guim.co.uk/35fd3…
#> $ legally_sensitive                <chr> "false", "false", "false", "fal…
#> $ sensitive                        <chr> "true", NA, NA, NA, "true"
#> $ lang                             <chr> "en", "en", "en", "en", "en"
#> $ body_text                        <chr> "Until last year, I identified …
#> $ char_count                       <chr> "2192", "1729", "12190", "4404"…
#> $ should_hide_reader_revenue       <chr> "false", "false", "false", "fal…
#> $ show_affiliate_links             <chr> "false", "false", "false", "fal…

See the full package documentation at docs.evanodell.com/guardianapi.

Meta

Please note that the ‘guardianapi’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

This package is not affiliated with or supported by The Guardian.

Metadata

Version

0.1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows