Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:25:15+00:00 2026-06-05T20:25:15+00:00

I created a sinatra based facebook app on Heroku by initiating it with the

  • 0

I created a sinatra based facebook app on Heroku by initiating it with the feature provided by Facebook (Get Cloud App or something like that). Everything worked fine, but when I tried to use the Scores from Facebook, I realized that the Facebook API used by Heroku (which is Mogli) does not support Scores.
So I tried to rewrite the code to use fb_graph. But since that created more confusion than everything I started with an empty file. But I just can’t make it work.

So basically I would like a simple example for a Sinatra based app on heroku which uses fb_graph. The samples should only contain authentication, since everything else seems pretty straight forward and has a lot of documentation. Just the initial authentication just doesn’t work.

I would like to use the default oauth2 approach with the callback, since it just feels more natural to me, but I’m open for everything. I know there is a Rails example, but I just can’t get my head around it and since my app will be very simple Rails seems a bit overpowered.

It would be great if anyone could give me just the few lines necessary for what I would like to do!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:25:17+00:00Added an answer on June 5, 2026 at 8:25 pm

    I’ve found this to be a bit of a mess. Old tutorials and code just don’t make sense anymore.

    You can use the Heroku + Facebook OmniAuth example to do an external website (not a canvas app) that does server-side Facebook (and many others) authentication.

    When you do that, OmniAuth will provide you with the token you need you need to pass to fb_graph. In the provided example you could add another url:

    get '/me' do
      me = FbGraph::User.me(session['fb_token']).fetch
      "Hello " + me.name
    end
    

    For canvas apps, I added the following code to ‘rack-facebook-request.rb’ to my repo based on this gist

    require 'base64'
    require 'openssl'
    require 'json'
    
    # This is inspired by [rack-facebook-signed-request](https://github.com/gamesthatgive/rack-facebook-signed-request)
    #
    # Usage
    #
    #     use Rack::FBSignedRequest, :secret => 'SECRET'
    #
    class Rack::FBSignedRequest
      def initialize(app, options)
        @app = app
        @options = options
      end
    
      def call(env)
        @request = Rack::Request.new(env)
        if @request.POST['signed_request']
          if facebook_params = parse_signed_request(@request.params['signed_request'])
            @request.params['facebook_params'] = facebook_params
            env['rack.request.query_hash'] = @request.params
            env['REQUEST_METHOD'] = 'GET'
            puts 'Valid signed request. Changed REQUEST_METHOD to GET.'
    
            if facebook_params['user_id']
              env['fb_user_id'] = facebook_params['user_id']
              env['fb_access_token'] = facebook_params['oauth_token']
              puts 'Request has been authorized.'
            else
              puts 'Request is not authorized.'
            end
    
          else
            puts 'Not a valid signed request'
          end
        else
           puts 'Not a signed_request'
        end
    
        @app.call(env)
      end
    
      private
    
      # The following code from omniauth
    
      def parse_signed_request(value)
        signature, encoded_payload = value.split('.')
    
        decoded_hex_signature = base64_decode_url(signature)
        decoded_payload = JSON(base64_decode_url(encoded_payload))
    
        unless decoded_payload['algorithm'] == 'HMAC-SHA256'
          raise NotImplementedError, "unkown algorithm: #{decoded_payload['algorithm']}"
        end
    
        if valid_signature?(@options[:secret], decoded_hex_signature, encoded_payload)
          decoded_payload
        end
      end
    
      def valid_signature?(secret, signature, payload, algorithm = OpenSSL::Digest::SHA256.new)
        OpenSSL::HMAC.digest(algorithm, secret, payload) == signature
      end
    
      def base64_decode_url(value)
        value += '=' * (4 - value.size.modulo(4))
        Base64.decode64(value.tr('-_', '+/'))
      end
    end
    

    This will give you the current fb_user_id and fb_access_token if your app is authorised. Remember that you have to use javascript or a link in the iFrame to request app authorisation in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create Sinatra based heroku app without any luck?
I'm not sure that I really understand how Sinatra works. I'd like to get
Scenario I have a Sinatra App I have a route that fetches articles based
I have a Sinatra based REST service app and I would like to call
I have an app file that looks like this ws_app.rb: require 'rubygems' require 'sinatra'
I have a Sinatra application I've created and I'd like to package it as
I recently created a Sinatra app with a login form (no basic auth). To
I have created an App on Heroku which works perfectly in a Web Browser.
I created a small chat application in Sinatra and jQuery on heroku. It simply
I'm starting my first Sinatra App and I'm trying to use DataMapper. Everything is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.