Step by Step guidance of Salesforce Youtube Integration

Step by Step guidance of Salesforce Youtube Integration
On January 27, 2020, Posted by , In Integration

Salesforce and YouTube both are very popular and powerful tools and their integration provides lots of benefits to the organizations.
This integration allows users to maintain the number of views, likes, dislikes, and comments for your favorite videos.

Why it is needed to integrate Salesforce and Youtube?

Track of useful statistics like ( number of likes and dislikes, number of views, number of comments) regarding your relevant YouTube videos is very much needed due to the evolving of Social Media Platform at one place, therefore nowadays organizations are adopting integration of two different tools to optimize their business flow.

Also check: How to Integrate Salesforce and Mailchimp Successfully?

Here is a list of useful steps to integrate Salesforce and Youtube using Salesforce REST API… 

  1. Creation of Objects and fields in Salesforce.
    • Create an object named ‘YouTube Video Details’ and subsequently create the tab for this custom object.
    • Inside this object, create fields named ‘Number of View Counts, Number of Likes, Number of Dislikes, Number of Comments, Video Id’ of text type.

    Salesforce Youtube Integration

  2. Formation of App.
    • Create an app named ‘YouTube Video Details’.
    • Add custom tab and object that you have created (in step 1) inside this app.

    Youtube Salesforce Integration

  3. The setting of Page Layout.
    • Put all the fields that you have created inside the object ‘YouTube Video Details’ on the page layout section.
    • Now Click on save.
  4. Getting of API Key.
    API_Google

    • Click on the URL https://console.developers.google.com in order to generate API Key and EndPoint.
    • Now Click on create the project and save it.
    • After that Click on Credentials present on the left-hand side menu.
    • Click on the Create credentials button. Select API KeY, it will be generated.
    • One pop up message comes, select close.
    • You can also rename the API Key name, not value.
    • Click on Dashboard present on the left panel and Enable API and Services.
    • The library of different API will come into the screen.
    • Click on YouTube Data API v3.
    • Now click on Try This API button, after enable this API.
    • Click on Videos present on the left panel you find the list in that videos section.
    • Put statistics in part section and in id part place id of any youtube video.
    • Click on the Execute button, now the statistics can be seen.

    YoutubeResponse

  5. Creation of Custom Settings
    • Create a custom setting named ‘ YouTube API Setting’.
    • Inside this custom, the setting creates one field named ‘Value’.
  6. Custom Settings 1

    • Click on the Manage button of that custom settings.
    • Click on New button.
    • Here create two fields named ‘YouTube API Key’ and ‘YouTube Endpoints’.
    • For YouTube API Key, put the API Key that you have created above in the value field and click on save.
    • For the YouTube Endpoints field, in value field put the value ‘https://www.googleapis.com/youtube/v3/videos?part=statistics%20&id={VIDEO_ID}&key={API_KEY}’ and click on save.

    Custom settings 2

  7. Creation of Remote Site Settings
    • Search for remote site settings in the quick find box and click on new.
    • In remote site name field put the value as ‘You_Tube_API_Setting’.
    • In the remote site, URL field puts the value as ‘https://www.googleapis.com’.
    • Click on the Save button.

    Remote_Site_Settings

  8. Creation of Custom Button and Apex Class
    • Click on the custom object that you have created just now.
    • Create a custom button named ‘Get Details’.
    • Use the javascript code for that button.
      {!REQUIRESCRIPT( “/soap/ajax/35.0/connection.js” )}
      {!REQUIRESCRIPT( “/soap/ajax/35.0/apex.js” )}
      var obj = {
      “videoId” :”{!Youtube_Video_Detail__c.Video_Id__c}” ,
      “recId” :”{!Youtube_Video_Detail__c.Id }”
      };
      sforce.apex.execute( “YouTubeVideoDetails”, “details”, obj);
      location.reload();
      
    • Create the Apex class with the name ‘YouTubeVideoDetails ’.
      Use the following Apex class…

      /*
       * This class runs the methods
       * that calls the YouTube API 
       * to get the details (likes,dislikes,comments,views) of
       * particular video that user want to see the video statistics 
       *
       */
      global class YouTubeVideoDetails {
               /**
               * This method Fetching the Encoded key and 
               * Endpoints by using the 
               * Custom Settings 
               */
          webService static void details( String videoId , String recId) {        
              String enckey = You_Tube_API_Setting__c.getInstance( 'YouTube API Key' ).Value__c;
              String endpt  = You_Tube_API_Setting__c.getInstance( 'YouTube Endpoints' ).Value__c;
              endpt         = endpt.replace( '{API_KEY}', enckey );
              endpt         = endpt.replace( '{VIDEO_ID}', videoId );
                      
              HttpRequest httpReq  = new HttpRequest();
              Http http            = new Http();
              HttpResponse httpRes = new HttPResponse();        
              httpReq.setMethod( 'GET' );
              httpReq.setEndpoint( endpt );        
              httpRes = http.send( httpReq );        
              JsonParser j = (JsonParser)JSON.deserialize(httpRes.getBody(),JsonParser.class);       
              Youtube_Video_Detail__c yv         = new Youtube_Video_Detail__c();
              yv.Id                       = recId;
              yv.Number_of_View_Counts__c = j.items[0].statistics.viewCount;//counts;
              yv.Number_of_Likes__c       = j.items[0].statistics.likeCount;
              yv.Number_of_Dislikes__c    = j.items[0].statistics.dislikeCount;
              yv.Number_of_Comments__c    = j.items[0].statistics.commentCount;        
              update yv;
          }
          public class JsonParser{
              public pageInfo pageInfo{get;set;}
              public String etag{get;set;}
              public list<items> items{get;set;}
              public String kind{get;set;}
          }
          public class statistics{
              public String viewCount{get;set;}
              public String likeCount{get;set;}
              public String dislikeCount{get;set;}
              public String favoriteCount{get;set;}
              public String commentCount{get;set;}
          }
          public class pageInfo{
              public Integer resultsPerPage{get;set;}
              public Integer totalResults{get;set;}
          }
          public class items{
              public String id{get;set;}
              public String etag{get;set;}
              public statistics statistics{get;set;}
              public String kind{get;set;}
          }
      }
      

Salesforce_and_YouTube__Integration_Details

Conclusion
Integration of Salesforce and Youtube helps sales reps to maintain all relevant statistics of YouTube videos like a number of likes and dislikes, number of views, and number of comments in one integrated system that is Salesforce CRM which further helps them to track all the relevant information.

Any query about this topic, We have a full staff of Salesforce Integration Consultant that can help you. Just drop us a message and let’s get free quotes.


AwsQuality helps businesses gain competitive edge with solutions on Salesforce cloud and mobile technologies with Offices Noida India, Louisiana focused customers are in the UK, US, Asia, South America and Australia.