403 - php TwitterOAuth


#1

I’ve set-up a dev environment with label dev for the premium 30day API sandbox, linked to my one and only app.
From my app, I request a Bearer Token successfully (via PHP TwitterOAuth), then issue a post request to
tweets/search/30day/dev.json and get the following:
Forbidden: Authentication succeeded but account is not authorized to access this resource.
I am certain the label corresponds to the dev environment, and I also tested with self-generated access token and access token secret: same issue.
What am I doing wrong?


#2

Hey @educach_de -

Could you try using this script to generate your bearer token instead?

require 'base64'
require 'httparty'
require 'json'

consumer_key = "YOUR_CONSUMER_KEY"
consumer_secret = "YOUR_CONSUMER_SECRET"

credentials = Base64.encode64("#{consumer_key}:#{consumer_secret}").gsub("\n", '')
url = "https://api.twitter.com/oauth2/token"
body = "grant_type=client_credentials"
headers = {
  "Authorization" => "Basic #{credentials}",
  "Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8"
}
r = HTTParty.post(url, body: body, headers: headers)
bearer_token = JSON.parse(r.body)['access_token']
puts "Twitter bearer token is: #{bearer_token}"

closed #3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.