Hearthstone

БЕСПЛАТНО
От omgvamp | Обновлено 24 days ago | Entertainment
Популярность

9.7 / 10

Задержка

2,330ms

Уровень обслуживания

100%

Health Check

N/A

Назад ко всем обсуждениям

Help with consuming the API using angularJS?

Rapid account: Msuarin
msuarin
8 years ago

Hi I was wondering if you can help with consuming this API through AngularJS. As an example, this is how I would consume a weather API from openweathermap.org:

$scope.weatherAPI = $resource(“http://api.openweathermap.org/data/2.5/forecast/daily”, { APPID: “822b2ab7395a69803904483f3b0c88a1”,
callback: “JSON_CALLBACK”}, { get: {method: “JSONP” }});

$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, cnt: $scope.days });

The JSON result would be stored in $scope.weatherResult.

I tried this with the hearthstone API but I’m not getting any results:

$scope.hsAPI = $resource(“https://omgvamp-hearthstone-v1.p.mashape.com/cards/Ysera”, { APPID: “dVJU44ytXLmshouErewLVrdVLz7vp1iBmABjsnesQ5qSalYnqa”,
callback: “JSON_CALLBACK”}, { get: {method: “JSONP” }});

$scope.hsResult = $scope.hsAPI.get();

I’m fairly new to AngularJS and consuming APIs in general so I’m sorry if this is a dumb question. Thanks.

Rapid account: Msuarin
msuarin Commented 8 years ago

Thanks man! I changed a few things there but that worked for me!

Rapid account: Omgvamp
omgvamp Commented 8 years ago

Disregard my previous message. You’ll have to do it slightly different since you can’t pass your Mashape API key when using JSONP. This is the correct solution:

function card($scope, $http) {
    $http.get('https://omgvamp-hearthstone-v1.p.mashape.com/cards/Ysera?callback=JSON_CALLBACK', {
	    headers: { 'X-Mashape-Key': 'MASHAPE_API_KEY_GOES_HERE' }
    }).success(function(data) {
        console.log(data);
    });
}
Rapid account: Omgvamp
omgvamp Commented 8 years ago

Hi!

This should work:

$http.jsonp('https://omgvamp-hearthstone-v1.p.mashape.com/cards/Ysera?callback=JSON_CALLBACK')
.success(function(data) { 
    console.log(data); 
});

Of course you still have to pass your API key etc.

Присоединяйтесь к обсуждению – добавьте комментарий ниже:

Войдите / Зарегистрируйтесь, чтобы публиковать новые комментарии