Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlcibiades Montas
5,974 PointsWhat does Javascript means?
Hi guys, currently building a Foursquare API script and looking over some code. I think I found something that will definitely help me but confused as to what exactly it does, can someone walk me over it?
var foursquareApi = {
clientId: "4B4T220TQF43NIUKJAQI1DNASEOI12NBTTUNZ5YOETDDQORF",
clientSecret: "YDBCTHJECBNMQVFWRC1GU5RFGGPHRY4Y1VGHSVD4PLMGRKNB",
redirectUrl : "http://almontas.github.io/FourSquareJax/",
//authorizes my app
authorize: function(){
var url = "https://foursquare.com/oauth2/access_token";
url += "?client_id="+this.clientId;
url += "&response_type=token";
url += "&redirect_uri="+this.redirectUrl;
this.getJson(url, function(data){
console.log("authorize",data);
}) //what does this do?
},
//gets Authentication Code
getCode : function(){
var url = "http://almontas.github.io/FourSquareJax/";
url += "#access_token=ACCESS_TOKEN";
this.getJson(url, function(data){
console.log("ACCESS_TOKEN",data);
}) //what does this do?
//gets parameter from above sends request back to API
},
getJson: function(url, callback){
$.getJSON(url, function(data) {
callback(data);
});//what does this do?
1 Answer
Daniel Tedman
Courses Plus Student 7,244 PointsThe first function is for authentication using using OAuth. If you are new to using OAuth, see the getting started guides.
It is not clear what the second function is for but it has something to to with the FourSquareJax page. It uses the authentication token retrieved in the first function.
The third function is convenience function they have written which uses the jQuery getJSON function to perform an AJAX request using the provided url and callback function. The callback function is called when the AJAX request has been completed.
My suggestion would be to study the documentation. The tricky bit is the authentication, once that is done, you make requests to each of the endpoints listed in the table on that site.