Question

I am making a request to the facebook graph api and have saved my USER_ID and ACCESS_TOKEN in ENV variables. I'm wondering if this is a best practice as this morning I am encountering a URI error that I was not getting yesterday.

class FacebookFeed
  #Constants
  VANDALS_ID = ENV['VANDALS_FB_ID']
  FB_ACCESS_TOKEN = ENV['FACEBOOK_ACCESS_TOKEN']
  FACEBOOK_URL = 'https://graph.facebook.com/"#{VANDALS_ID}"/posts/?access_token="#{FB_ACCESS_TOKEN}"'

def get_feed
  uri = URI(FACEBOOK_URL)
  response = HTTParty.get(uri)
  results = JSON.parse(response.body)['data']
  puts results
end
end

So in the Rails console I am just trying to get a response but am getting:

URI::InvalidURIError: bad URI(is not URI?): https://graph.facebook.com/"#{VANDALS_ID}"/posts/?access_token="#{FB_ACCESS_TOKEN}"

This is strange as this was working yesterday. Is there anything I am missing or is there a better way to store my User_ID and Access Token?

Update

When doing a 'puts uri' this is returned:

https://graph.facebook.com/%22%23%7BVANDALS_ID%7D%22/posts/?access_token=%22%23%7BFB_ACCESS_TOKEN%7D%22

I assume this is what is being sent as the GET request, because when I then do 'puts response' I get:

{"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}

How do I construct the request correctly?

Was it helpful?

Solution

After talking to Rich on Skype, the problem was resolved with Sergey Kishenin's comment:

FACEBOOK_URL = "https://graph.facebook.com/#{VANDALS_ID}/posts/?access_token=#{FB_ACCESS_TOKEN}"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top