Using httr2 with OAuth 1.0 Authentication

40 Views Asked by At

I've been given access to a cool API -- yay! But the authentication information I've been given doesn't seem to match anything I can find in the httr2 documentation.

I've been given these four values:

Consumer Key Consumer Secret Access Token Token Secret

And a URL: https://api.gunviolencearchive.org/api/incidents.json

The instructions say to include full authentication in the header with each request, and to include a throttle. There is no time limit, apparently, once a token is obtained.

I am new at this, so please be gentle.

Thanks so much!

I tried the following with httr, because there seems to be more documentation on using httr with Oauth 1.0, but got "request must be signed":

library(httr)

headers = c(oauth_consumer_key="###",oauth_token="###",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1709088023",oauth_nonce="pqgWMz9XJG8",oauth_version="1.0",oauth_signature="ISnTuPVk8dtV6xj4%2F8C9BrQ7CYU%3D",
  'Cookie' = 'SSESSadcf082155f3ed84e8258635a32052e6=rmAn_wGCIrk8VvALtc352qXuwGZEG0pYlJvuaYmwnK0'
)

res <- VERB("GET", url = "https://api.gunviolencearchive.org/api/incidents.json?pagesize=40000&filters[IncidentDate][method]=is year&filters[IncidentDate][field][date-year]=2015&truncation_limit=0", add_headers(headers))

cat(content(res, 'text'))

0

There are 0 best solutions below