Search Guardian API for news articles that match the criteria
The function get_guardian takes four variables (keyword(s), starting date, end date, and API-key) and returns a data frame with 27 columns, with the last column including the full text of the article.
Search criteria accepts single or multiple keywords concatenated with "+" (e.g. "keyword1+keyword2"). It also accepts Boolean queries with and/or/not between words to refine searches. For exact phrases and matches, please encapsulate the keywords in %22 (e.g "%22Death+of+Margaret+Thatcher%22").
From version 0.5 onwards, the function get_guardian returns the full text of articles and requires a Guardian API-key. Guardian API-key can be obtained by registering at <http://open-platform.theguardian.com/access/>.
get_guardian(keywords, section, format, from.date, to.date, api.key)
Keyword to search Guardian API. Example: "Thatcher". For multiple keywords use "Margaret+Hilda+Thatcher".
Specifies news sections to narrow the query (articles from other news desks will be filtered out). It doesn not accept blank spaces, so use "world" if querying for articles in the section "world news" (and so on). It defaults to NULL in which case the API request is performed across all sections. For referece, these are some of the most common news sections:
Specifies JSON or XML format. It defaults to JSON.
Start date of search.
End date of search.
A Guardian API-key is necessary to retrieve the full text of news articles. A Guardian API-key can be obtained by registering at <http://open-platform.theguardian.com/access/>.
Returns a data frame with 27 variables. Rows refer to news articles and columns to the news item's data.
Marco Bastos & Cornelius Puschmann
Information about the Content API is available on Guardian Item Reference Guide (http://open-platform.theguardian.com/documentation/).
1 2 3 4 5 6 7
## Not run: results <- get_guardian("islamic+state", section="world", from.date="2014-09-16", to.date="2014-09-16", api.key="3xzg2fk53jcdgaj5tbwqqhcz") ## End(Not run)