Raoot
Raoot

Reputation: 1771

Rails 3.1 - Facebook Page API calls

I have the following working perfectly for calls to Facebook pages with simple URLS like: www.facebook.com/TurbonegroHQ

  def get_facebook
    @artist = Artist.accessible_by(current_ability).find(params[:id])
    if @artist.facebook_url.present?
      require 'open-uri'
      require 'json'
      result = JSON.parse(open("https://graph.facebook.com/"<<@artist.facebook_url).read)
      @hometown = result["hometown"]
      @band_members = result["band_members"]
      @likes = result["likes"]
    end
  end

However, when a Facebook page URL isn't in this format, but something like https://www.facebook.com/pages/Clutch-The-Bakerton-Group-Weathermaker-Music/16637738637 it fails. Any ideas how I can get around this?

Thanks in advance?

Upvotes: 0

Views: 242

Answers (1)

Igy
Igy

Reputation: 43816

TurbonegroHQ is the username of the page - this is interchangeable with the object ID in the Graph API.

If the page doesn't have a username you need to access it via the ID instead. In that case https://graph.facebook.com/16637738637 is the URL to access

Usually you'll have IDs rather than the URLs as the ID is returned in the API on all the endpoints I can think of

Upvotes: 1

Related Questions