Search code examples
rubyurlfoursquareaccess-token

Parse the callback URL from foursquare?


I am trying to parse the URL returned from the foursquare api (the callback URL) the problem is that the request comes in this format

0.0.0.0:4567/foursquare#access_token=KCZGA4JIR4N3QXXAASZTZRYWHU2TYJITM53LARSKHRVFPHQ

as you can see that hashtag is breaking havoc in my code because is nowhere to be found using request.url or the whole request object for that matter.

Has anyone solved this? I am not trying to authenticate, I already do that from inside the iOS app.

require 'sinatra'
require 'json'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-migrations'
require 'dm-ar-finders'

# where foursquare sent us after authorization
get "/foursquare" do
    puts "Receiving ..." + request.url
end

Solution

  • Probably not what you want to hear, but a quick fix would be let your Sinatra (assuming that given your port number) do the authentication instead of the iOS app. This way you can take advantage of the omniauth-foursquare gem, https://github.com/arunagw/omniauth-foursquare/blob/master/lib/omniauth/strategies/foursquare.rb, which will do most of the parsing for you.

    According to Foursquare's API page, https://developer.foursquare.com/resources/client, they recommend doing a web-based authentication too.