[Rails] Twitch api returns 404 instead of user name

New thing… I have 2 methods:

  def getUserName
    #get user name
    params = {
      'client_id' => @client_id,
      'oauth_token' => @token
    }
    name_info = Net::HTTP.post_form(URI.parse('https://api.twitch.tv/kraken/channel'), params)
    @nickname = JSON.parse(name_info.body)["display_name"]
    @nickname.downcase! if @nickname != nil
  end
  def getUserToken
    #get user access_token
    params = {
      'client_id' => @client_id,
      'client_secret' => @client_secret,
      'grant_type' => @grant_type,
      'redirect_uri' => @redirect_uri,
      'code' => @code
    }
    token_info = Net::HTTP.post_form(URI.parse('https://api.twitch.tv/kraken/oauth2/token'), params)
    @token = JSON.parse(token_info.body)["access_token"]
  end

getUserToken works pefectly, while getUserName returns 404. WHY?
Token is good and works while I check manually… But request returns json 404 :frowning:

Ok, Im retarded… It just need ‘get’ instead of ‘post’… Solution:

  def getUserName
    #get user name
    name_info = Net::HTTP.get(URI.parse("https://api.twitch.tv/kraken/channel?oauth_token=""#{@token}"))
    @nickname = JSON.parse(name_info)["display_name"]
    @nickname.downcase! if @nickname != nil
  end

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.