Tag Archives: api

API Homework

Finally getting the hang of this. Thank you for going over it again Master P, really helped.
For anyone in the class who missed it and is looking for it here is what we went over in the review friday:

http://cssdeck.com/labs/ke0mp2in

Here is the code, I got my own key and pulled the weather forecast for my Home town of Wagram North Carolina:

Raw Data link:

http://api.wunderground.com/api/dc48a9b9b5d76b6a/forecast/q/NC/Wagram.json

Script:

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>JSON WITH API: Astronomy 1</title>

<script type=”text/javascript” src=”js/jquery-1.10.2.min.js”></script>

<script type=”text/javascript”>

/*Standard request URL format =
http://api.wunderground.com/api/b79e3040f6431025/features/settings/q/query.format
where
features=> type of data, here astronomy
settings=> lang or personal data
query=> location of data
*/

$(document).ready(function(){
$.ajax({
url: “http://api.wunderground.com/api/dc48a9b9b5d76b6a/forecast/q/NC/Wagram.json&#8221;,
dataType : “jsonp”, //jsonp for cross-origin files
success : function(parsed_json) {
console.log(‘success!!’);
//each nested object goes in []
var wagramWeather = parsed_json[‘forecast’][‘txt_forecast’][‘forecastday’][1][‘fcttext’];
var wagramWeatherday2 = parsed_json[‘forecast’][‘txt_forecast’][‘forecastday’][3][‘fcttext’];

$(“#container”).append(“Here is the forecast for the place I was born and raised(Wagram, NC): “+wagramWeather);

$(“#container2”).append(“Wednesday in Wagram will be: “+wagramWeatherday2);

} //end of success
}); //end of ajax
}); //end of doc ready

 
</script>

</head>

<body>
<section id=”container”>
<
</section>
<section id=”container2″>

</section>
</body>
</html>

Leave a comment

Filed under Homework

HW3- Soundcloud API

I explored the Soundcloud API (http://developers.soundcloud.com/docs/api/guide#playing) to create a simple code that should stop/start a song within a web player.

This is the song: https://soundcloud.com/takugotbeats/love-lost-daughter-edit?in=likethislikezach/sets/pillowtalk

Here’s the link to my server: http://a.parsons.edu/~zhuc966/API%20test/#

For some reason, it works when I code it into the CodeAcademy tutorial using the song’s unique track number but not on my server and I think it has to do with some SC licensing/attributes that I’m not coding properly into the html.

<!doctype html>
<html>
<head>
<script src=”//connect.soundcloud.com/dsk.js”>

SC.initialize({
client_id:’34da89712251a6bbebad6206d22bf933′
redirect_uri:’https://soundcloud.com/connect&#8217;
});

$(document).ready(function(){
SC.stream(‘/tracks/93317308’, function(sound){
//unique track url for each song
$(‘#start’).click(function(e){
e.preventDefault();
sound.start();//sound function starts on id start
});
$(‘stop’.click(function(e){
e.preventDefault();
sound.stop();//sound function stops on id stop
}))
});
});
</script>

</head>
<body>
<a href=”#” id=”start”>Play</a>
<a href=”#” id=”stop”>Stop</a>
</body>

</html>

Leave a comment

Filed under Uncategorized