Harsh Vardhan
Giga Patron

We can integrate Service-now with YouTube by using google API.

Here i tried to Retrieve one of the YouTube Video "View Count" , "Likes", "Number of Comments".

 

Steps:

  • You need to check the API from https://console.developers.google.com.
  • once you access the above URL then you need to create a Project.

find_real_file.png

 

if you see i have already create one project as "ServiceNow Dev". same way you can create your new project.

Once you will create the project then go to the "Credentials" and click on edit icon to copy the API Key.

 

find_real_file.png

 

Once you will be done with above steps then you will use the "YouTube.videos.list" API to get the YouTube videos count, like , or other details related to video.

if you want to learn more about the YouTube API you can refer the below link.

https://developers.google.com/apis-explorer/#s/

 

Now i am coming to the Service-now , here i have used rest message.

Rest Message:

 

find_real_file.png

 

find_real_file.png

 

Business rule i used :

 

(function executeRule(current, previous /*null when async*/) {
	
	// Add your code here
	try {
		var r = new sn_ws.RESTMessageV2('youtubeApi', 'Default GET');
		r.setStringParameterNoEscape('YOUR_API_KEY', 'AIzaSyBcvG_6AknJN30yT4y9RSOqncVOe0gW_Ns');
		r.setStringParameterNoEscape('video_id',current.u_video_id);
		var json = new global.JSON();	
		var response = r.execute();
		var responseBody = response.getBody();
		var httpStatus = response.getStatusCode();
		gs.log('check status'+httpStatus);
		var decodedResponse = json.decode(responseBody);
		var check = decodedResponse.items.length;
		for(var i=0; i<check; i++)
			{
				gs.log('hey hey'+decodedResponse.items[i].statistics.viewCount);
				var gr = new GlideRecord('u_youtube_applciation');
				gr.get(current.sys_id);
				gr.u_video_view_count=decodedResponse.items[i].statistics.viewCount;
				gr.u_number_of_likes=decodedResponse.items[i].statistics.likeCount;
				gr.u_video_comment_count=decodedResponse.items[i].statistics.commentCount;
				gr.update();
			}
		
		
		
	}
	catch(ex) {
		var message = ex.message;
	}
	
})(current, previous);

 

i have created one custom table with the columns "Video ID" , "Video Count", "Number of Likes" , "Video Comment Count".

find_real_file.png

 

so here i will simply pass the YouTube video id and based on that it will fetch the number of details.

Example : I opened any youtube video and copied the id and paste it in my "Video Id" field then it will give me the details like below.

 

find_real_file.png

if you see the number of likes, views comment count came in my fields.

find_real_file.png

 

many other integration we can do by using google API with service-now.

 

Thanks,

Harshvardhan

 

 

 

 

12 Comments