function get_photo_comments()

in assets/www/scripts/photark_flickr.js [13:79]


function get_photo_comments(photoID){
	var comments="";
	var foo = new Date; // Generic JS date object
    var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
    var unixtime = parseInt(unixtime_ms / 1000);
	var method='flickr.photos.comments.getList';
	var oauth_nonce=$.md5(unixtime.toString()+Math.floor((Math.random()*40)+1).toString());
	console.log(oauth_nonce);
	var baseSign = "GET" + "&" + encodeURIComponent("http://api.flickr.com/services/rest").toString() + "&"+encodeURIComponent("content_type") + "%3D" + encodeURIComponent('1')
     + "%26"+ encodeURIComponent("format") + "%3D" + encodeURIComponent('json')
     + "%26"
	 + encodeURIComponent("method") + "%3D" + encodeURIComponent(method)
	 + "%26"+ encodeURIComponent("nojsoncallback") + "%3D" + encodeURIComponent('1')
	 + "%26"+ encodeURIComponent("oauth_consumer_key") + "%3D" + encodeURIComponent(api_key)
     + "%26"
     + encodeURIComponent("oauth_nonce") + "%3D" + encodeURIComponent(oauth_nonce)
     + "%26"
     + encodeURIComponent("oauth_signature_method") + "%3D" + encodeURIComponent("HMAC-SHA1")
     + "%26"
     + encodeURIComponent("oauth_timestamp") + "%3D" + encodeURIComponent(unixtime)
	 + "%26"
     + encodeURIComponent("oauth_token") + "%3D" + encodeURIComponent(oauth_token)
     + "%26"
     + encodeURIComponent("oauth_version") + "%3D" + encodeURIComponent("1.0")+ "%26"
     + encodeURIComponent("photo_id") + "%3D" + encodeURIComponent(photoID);
	console.log(baseSign);
	var secret_key=secret+'&'+oauth_token_secret;
	console.log(secret_key);
	var oauth_signature = encodeURIComponent(b64_hmac_sha1(secret_key, baseSign)+'=');
	console.log(oauth_signature);
	var url='http://api.flickr.com/services/rest?nojsoncallback=1&oauth_nonce='+oauth_nonce+'&format=json&oauth_consumer_key='+api_key+'&oauth_timestamp='+unixtime+'&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token='+oauth_token+'&photo_id='+photoID+'&oauth_signature='+oauth_signature+'&method='+method;
	console.log(url);
	$.ajax({
		url:url,
		success: function(data) {
					console.log(data);
					if(data.comments.comment===undefined)
					{
						comments="No comments";
					}
					else
					{
						data.comments.comment.forEach(function(item){
							if(item.id===undefined)
							{
								comments='No comments';
							}
							else
							{
								comments+=item.authorname+": "+item._content+"\r\n";
								console.log(comments);
							}
						});
					}
				},
		error: function( error ){

				    	// Log any error.
						alert("ERROR1:"+error.responseText);
				    	console.log( "ERROR:"+error.responseText,error);

				},
		async:false
	});
	console.log(comments);
	return comments;
}