title: API 1.1 requesting twitter bearer token using r
body: <p>I have searched this forum and tried several things that seemed relevant, but with no success. If anyone can spot what I'm missing I would be very grateful.</p>
  
  <p>I am trying to get a bearer token using application only authorization as explained at <a href="https://dev.twitter.com/docs/auth/application-only-auth" rel="nofollow">https://dev.twitter.com/docs/auth/application-only-auth</a> so that I can GET follower s/ids.</p>
  
  <p>I have constructed a request in r using rstudio with my consumer key &amp; secret in Base64 encoded form.</p>
  
  <pre><code>library(httr)
  POST(url="https://api.twitter.com/oauth2/token", config=add_headers(
  c('Host="api.twitter.com"',
  'User-Agent="NameOfMyApp"',
  'Authorization="Basic MyKeyandSecretBase64Encoded"',
  'Content-Type="application/x-www-form-urlencoded;charset=UTF-8"',
  'Content-Length="29"',
  'Accept-Encoding="gzip"')), body="grant_type=client_credentials")
  </code></pre>
  
  <p>In response I receive:</p>
  
  <pre><code>Response [https://api.twitter.com/oauth2/token]
  Status: 403
  Content-type: application/json; charset=utf-8
  {"errors":[{"label":"authenticity_token_error","code":99,"message":"Unable to verify your credentials"}]}
  </code></pre>
  
  <p>I tried resetting my credentials but it made no difference.</p>