ruby on rails - JSON::ParserError 757 Unexpected token -


a little background on i'm working on. i'm trying create app spice coding portfolio can't app work me. followed guide part of it, integrating steam openid/omniuath ruby on rails since uses post no csrf token....yadda yadda yadda. anyhoo, i'm trying far upon logging in through steam, moment, list of players owned games display. it's not working me. code below controller.

    class welcomecontroller < applicationcontroller   skip_before_filter :verify_authenticity_token, :only => :auth_callback   def index     @gameslibrary = []     if session.key? :current_user     url = uri.parse("http://api.steampowered.com/iplayerservice/getownedgames/v0001/?key=#{env['steam_web_api_key']}&account_id=#{session[:current_user][:uid]}")     res = net::http::get(url)     @gameslibrary = json.parse(res)['game_count']['app_id']['name']['playtime_forever'] || []   end end   def auth_callback       auth = request.env['omniauth.auth']       session[:current_user] = { :nickname => auth.info['nickname'],                                             :image => auth.info['image'],                                             :uid => auth.uid }       redirect_to root_url     end end 

and here view code

<h1>welcome#index</h1> <%= link_to image_tag("http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png"), '/auth/steam' %> <% if session.key? :current_user %> <h3>current user:</h3> <%= image_tag session[:current_user][:image] %> <p><%= session[:current_user][:nickname] %></p> <p><%= session[:current_user][:uid] %> </p> <% end %> <ul>   <% @gameslibrary.each |game| %>   <li><%= puts game %></li>   <% end %> </ul> 

my json parse comes following

757: unexpected token @ '<html> <head> <title>500 internal server error</title> </head> <body> <h1>internal server error</h1> </body> </html>' 

now steam web api support json output. , items after json parse actual names of arrays/items in arrays. doing wrong here? , more how convert the json parse data array hash? (or automatic?) i'm new of , first app i've done on own. i'm using getownedgamesv0001 steam web api if wants @ it.

the problem sure response, invalid json, can first of move code model check response code url try send request if different 200 don't try json.parse response because error now.

do like:

url =      uri.parse("http://api.steampowered.com/iplayerservice/getownedgames/v0001/?key=#{env['steam_web_api_key']}&account_id=#{session[:current_user][:uid]}")  if net::http.get_response(url).kind_of? net::httpsuccess   @gameslibrary = json.parse(net::http::get(url))['game_count']['app_id']['name']['playtime_forever'] || [] else   ... raise or log or ... end 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -