2017-08-30 58 views
0

我似乎當我運行我的應用程序將得到一個錯誤:如何顯示從API的結果,以在軌的意見5

getaddrinfo: Name or service not known 

我認爲錯誤的原因有應用程序之間沒有任何聯繫以及使用服務檢索api的服務器。我使用RestClient gem來訪問請求。

#services/get_games.rb 
class GetGames 
    def self.get_games 
    response = RestClient::Request.execute(
     method: :get, 
     url: 'https://api-2445582011268.apicast.io.json', 
     headers: {user_key: ENV["IGDB_API"], accept:'application/json'} 
    ) 
    end 
end 

#games_controller 
def index 
    @response = JSON.parse(GetGames.get_games) 
    @games = Game.all 
end 
+0

您收到的錯誤是因爲https://api-2445582011268.apicast.io.json是無效的域名。 – Leito

+0

域名是Okey。看來我的錯誤是我錯誤地傳遞了標題。它的工作原理:) –

+0

'io.json'不是一個有效的域,但是,我很高興你使它成功。 – Leito

回答

1

我覺得如果你在url起飛.json,錯誤就會消失。

+0

沒有解決問題...現在得到403:禁止的錯誤 –

+0

所以看來你需要正確的憑據。 – hashrocket