How to Get a YouTube API Key [Tutorial + Examples]

文章推薦指數: 80 %
投票人數:10人

Developer using the YouTube API to connect their website to YouTube ... listed on the API & Services dashboard in Google Developers Console. Website|15minread HowtoGetaYouTubeAPIKey[Tutorial+Examples] WrittenbyAnnaFitzgerald BONUSCONTENT:18FreeYouTubeTemplatesforBusinessGettheFreeYouTubeTemplates Goodnews:There'saneasywaytouseYouTubetogrowyourbusinesswithoutcreatingvideos.YoucanembedexistingYouTubecontentonyoursiteusingtheYouTubeAPI. Noscripting,nostoryboarding,andnofilmingrequired.Justusethecontentthathasalreadybeencreated.Let’stakealookatwhattheYouTubeDataAPIis,howyoucangetanAPIkey,andhowyoucanuseitforyourbrand. WhatistheYouTubeAPI? TheYouTubeAPIisanapplicationprogramminginterfacethatallowsyoutoembedvideos,curateplaylists,andofferotherYouTubefunctionalitiesonyourwebsite.Ithelpsbusinessesofferadvancedvideosharingfeaturesontheirwebsiteorappwithoutneedingtowritecodefromscratch. LikeotherAPIs(orApplicationProgrammingInterfaces),theYouTubeAPImakesaprogrammer’sworkeasierbyskippingthedrudgeryofwritingeverysinglelineofcodeeverytimeusersneedtoaccessdata.Instead,programmerscanusepredefinedfunctionsandprotocolstocurateYouTubevideosonawebsite. Additionally,theYouTubeAPIhasawideselectionoffeaturesandfunctionalitiesthatmakeitaccessibletodevelopersandvaluabletobusinesses.Itallowsyoutoretrievedataatamassscalewithoutneedingtoaccessindividualvideosandchannels. Withthatinmind,whatkindofdatacanyoufeatureusingtheYouTubeAPI?Let’stakealook. YouTubeAPIData TheYouTubeAPIgivesyouaccesstoYouTube’sdatainamorecomprehensive,scalablewaythanstandaloneYouTubeembedcodeswould.Youcanretrieveentireplaylists,users’uploads,andevensearchresultsusingtheYouTubeAPI.YoucanalsoaddYouTubefunctionalitiestoyourwebsitesothatuserscanuploadvideosandmanagechannelsubscriptionsstraightfromyourwebsiteorapp. Let’stakealookatsomeofthemostpopularfunctionalitiesoftheAPI.Thisisnotanexhaustivelist;werecommendperusingGoogle’sofficialdocumentation. YouTubeResource ExampleHTTPRequest Description i.ewhatyou’dliketousetheAPIfor i.eonepossiblerequestyoucouldmakewiththisresource i.ewhattheactionwouldlooklikeonyourwebsiteorapp YouTubeSearch GET/search Retrievesarangeofsearchresultsbasedonthequeryyou’veset. YouTubePlaylists DELETE/playlists Deletesaplaylist. YouTubeVideos POST/videos UploadsavideotoYouTubefromyourwebsiteorapp. YouTubeComments POST/comments/markAsSpam Allowsyoutoflagoneormorecommentsasspam. YouTubeChannels GET/channels Retrievesachannel’svideosorplaylists(oranyotherresource,suchascomments). YouTubeSubscriptions POST/subscriptions Addsasubscribertoanauthenticateduser’schannel. YouTubeChannelMembers GET/members Retrievesalistofmembersforachannelthathasgivenyouauthorization. YouTubeCaptions PUT/captions Updatesacaptiontrack(youcanuploadanewfileorchangeittoadraft). YouTubeChannelSections POST/channelSections Allowsyoutoaddasectionoffeaturedvideos,forexample,toanauthenticateduser’schannel. YouTubeWatermarks POST/watermarks/unset Allowsyoutoremoveawatermarkimageassociatedwithachannel. BenefitsofUsingtheYouTubeAPI ManymarketersandbusinessownersaremissingoutonthebenefitsofincorporatingYouTubeintotheirdigitalmarketingstrategy.Usually,it'saquestionofhowmuchtimeittakestocreatehigh-qualityvideocontent. InatypicalYouTubemarketingstrategy,youwouldconsistentlypublishvideocontenteveryweekwiththehopesofgeneratinglikesandsubscribers—aportionofwhichyou’dhopewouldconvertintocustomers.Luckily,thisisnolongertheonlywaytouseYouTubeforyourbusiness.YouTubehascreatedanAPIthatallowsyoutointegrateyourwebsitewiththesocialplatform. HerearesomeofthegreatestbenefitsofusingtheYouTubeAPI: Youcantakeadvantageofexistingcontent.WiththeYouTubeAPI,youdon’thavetospendvaluabletimeandresourcescreatingcontent.Instead,youcantakeadvantageofthecontentthathasalreadybeenpublishedtoincreaseuserengagementonyoursite. YouTubeisoneofthetopsocialmediaplatforms.Withmorethantwobillionactiveusersinmorethan100countries,YouTubeisthetopvideostreamingapp.It'salsothesecond-largestsearchengine,thesecondmostpopularsocialplatform,andthesecondmostvisitedsiteontheinternet. FeaturingYouTube’scontentcanincreaseyourdwelltime.BecausetheYouTubeAPIcanhelpyouaddYouTubecontenttoyourwebsite,itwillhelpusersstayonthepageforlongerastheywatchthecontentthatyou’vespecificallycuratedforthem.Thisincreaseindwelltimesignalstosearchenginesthatyourcontentisvaluable,boostingyourrankingsfortargetkeywords. UsingtheAPIcanhelpyouconvertmorewebsitevisitors.UsingtheAPIisalsovaluablefromaconversionrateandrevenuestandpoint.Prospectswhoengagewithyourcontentandstayonyourwebsitearemorelikelythannottomakeapurchase. UsingtheYouTubeAPIisano-brainerformanymarketers,butYouTubedoesn'tallowjustanyonetoaccessthisvaluabletooloritsdata.Topreventpotentialabuse,YouTubegrantseachuserauniqueAPIkeythatallowsthemtoconnecttheirwebsiteorapptotheplatform. EachAPIkeyisdesignatedforanindividualproject.Ifyou’reusingtheAPIontwodifferentwebsites,youshouldcreatetwodifferentAPIkeys. Now,let’sgooverhowtogetaYouTubeAPIkeystep-by-step. HowtoGetaYouTubeAPIKey LogintoGoogleDevelopersConsole. Createanewproject. Onthenewprojectdashboard,clickExplore&EnableAPIs. Inthelibrary,navigatetoYouTubeDataAPIv3underYouTubeAPIs. EnabletheAPI. Createacredential. AscreenwillappearwiththeAPIkey. Ifyou'dprefertowatchavideo,checkoutthiswalkthroughbyDAIMTODevelopertips: 1.LogintoGoogleDevelopersConsole. YoucanlogintoGoogleDevelopersConsoleusingyourGoogleaccount.Ifyoudon’tyethaveone,you’llneedtocreateone. 2.Createanewproject. Onceyoulogin,you’llautomaticallybetakentoanemptydashboard.Ontheupperright-handcorner,clickCreateProject. ImageSource You’llbetakentoascreenwhereyoucanaddaprojectname,selectyourorganization,andselectalocation(URL). Youcancreateaprojectwithoutanorganization.Ifyoudon’thaveanorganization,youwon’tbepromptedtoselectalocation. ImageSource Onceyoucreateaproject,everythingyoudofromhereonwards,includingcreatingtheAPIkey,willapplytothatspecificproject.Ifyouhavemultipleprojectsgoingatthesametime,ensurethatthecorrectoneisselectedbydouble-checkingthattheprojectislistedonthetopnavigationbar. 3.Onthenewprojectdashboard,clickExplore&EnableAPIs. Aftercreatingaproject,you’llbetakentoabrandnewdashboardwithdifferentcards:ProjectInfo,Resources,andsoon. NavigatetotheGettingStartedcardandclickonExplore&EnableAPIs. ImageSource Alternatively,onthesidebar,navigatetoAPIs&Services>Library. 4.Inthelibrary,navigatetoYouTubeDataAPIv3underYouTubeAPIs. Onceyou’vereachedthelibrary,you’llseeapagedividedintosections.NavigatetothesectiontitledYouTubeAPIsandselectYouTubeDataAPIv3. ImageSource Alternatively,youcansearchfortheYouTubeDataAPIonthesearchbar. 5.EnabletheAPI. AfteryouarriveattheYouTubeDataAPIpage,clickabluebuttonwiththewordEnable. ImageSource 6.Createacredential. AfterclickingEnable,you’llbetakentoanoverviewpage. ImageSource Onthetoprightcorner,clickCreateCredentials. OntheCredentialswindow,selectYouTubeDataAPIv3forthefirstblankspace,Webserver(e.g.nodejs.Tomcat)forthesecond,andcheckthePublicdataboxonthethirdprompt. ImageSource Rightbelowthat,clickonthebluebuttontitledWhatcredentialsdoIneed? Afterthat,yourAPIkeywillautomaticallyload. ImageSource ClickDone. 7.AscreenwillappearwiththeAPIkey. Finished!You’vegotyourAPIkey.It’ssavedinyourcredentialsforeasyretrieval. ImageSource YouTubeAPIKeyTroubleshooting WhereisMyYouTubeAPIKey? HaveyoucreatedanAPIkeybutdon’tknowhowtofindit?We’llwalkyouthroughtheprocessoffindingitstep-by-step. Step1:LogintoGoogleDevelopersConsole. Step2:You’llautomaticallybetakentoyourprojectdashboard,whereyou’llseeaseriesofcards.UndertheAPIscard,clickGotoAPIsoverview. ImageSource Step3:You’llbetakentoadashboardwithasidebar.Onthissidebar,clickCredentials. ImageSource Step4:Alldone!You’llfindtheYouTubeAPIkeyyoucreated. ImageSource MyYouTubeAPIKeyisNotWorking Glitcheshappenallthetime,especiallywhenitcomestoAPIs. YourAPIkeymaynotbeworkingbecauseyou’reusingitforthewrongproject.Besureyou’reusingthekeyfortheprojectthatyoucreateditfor,especiallyifyoucreatedmultipleprojectsatthesametime. Ifit’sstillnotworking,considercreatinganewAPIkeyentirely. Onceyou’veretrievedyourYouTubeAPIkey,youcanuseittocallYouTube’sdata.Oneotherhighlybeneficialuseislive-streamingeventsforyourbusiness.ThiswillrequireyoutoaccesstheYouTubeLiveStreamingAPI. HowtoAccessYouTubeLiveAPI 1.Followsteps1-7abovetogetaYouTubeAPIkey. First,setupyourproject,website,orappandthengetaYouTubeAPIkey.ThiskeywillletyouaccessYouTube’sLiveStreamingAPI. Don’tforgettoregisteryourappwithGooglesothatyourAPIrequestsaresuccessfullyauthenticated. 2.LearntheresourcesassociatedwiththeYouTubeLiveAPI. TheYouTubeLiveStreamingAPIhasadistinctsetofresourcesyoucanmakeAPIcallsfor.Theseinclude: liveBroadcastreferstothemetadataofyourliveYouTubevideo. liveStreamreferstotheactualcontentyou’llbetransmittingduringyourliveevent. liveCuepointreferstoanadbreakinyourlivevideo. TheYouTubeLiveAPIalsosharessomeresourceswiththeYouTubeDataAPI,including: videoreferstoasingleYouTubevideo. videoAdvertisingOptionsreferstotheadsettingsforyourbroadcast. assetreferstoapieceofintellectualproperty(suchasascenefromamovieorshow)that’snotownedbyyou. policyreferstoanyrulesorpoliciesthatyourlivebroadcastorYouTubevideoisunder. 3.Learnwhatyoucandowithcertainresources. Foreachoftheseresources,youcancompleteacertainsetofactions,whicharecalled“methods.”Themethodsyoucanusewillvarydependingontheresourceyou’retryingtocreateanAPIcallfor. Forinstance,youcandothefollowingwithaliveBroadcastresource: list:Allowsyoutoretrievearangeofbroadcaststhatmatchyourrequestparameters. insert:Allowsyoutocreatealivebroadcast. update:Allowsyoutochangealivebroadcasts’metadataorsettings. delete:Allowsyoutodeleteabroadcast. Andmuch,muchmore.Italldependsonwhatexactlyyou’retryingtodo.Ifyou’refeelingatalossanddon’tknowhowtousetheYouTubeLiveStreamingAPIfor,say,yourWordPresswebsite,youmightconsiderusingapluginsuchasWPYouTubeLive. 4.TryitoutusingGoogle’sAPIexplorertool. Beforeyoutouchasinglelineofyourcodeonyouractualapporwebsite,tryouttheLiveStreamingAPIusingGoogle’sbuilt-inAPIexplorertool.Init,youcanspecifyparameterssuchasbroadcastStatus,broadcastType,pageToken,andmore(butthefieldswillvarydependingontheresourceandmethodyou’retesting).Thisallowsyoutodraftupthecodeinasandboxenvironmentwithoutmanipulatingthecodeyou’vealreadywrittenforyourwebsiteorapp. Ifyou’relookingformoregeneralexamplesoftheYouTubeDataAPI,you’reinluck.Below,wesharesomecodesamplesforcommonthingsyoumightwanttodousingtheAPI. YouTubeAPIExamples WhataresomeotherwaysyoucanusetheYouTubeAPIonyourwebsiteorapp?Below,you’llfindusefulcodesamplesforcommonYouTubeAPIusecases. 1.RetrievingYourUploads Thefollowingcodesamplesallowyoutoretrieveyourownoranotheruser’suploads.Choosetheonethatalignswiththecodinglanguageorplatformyou’reusing. AppsScript SeethePenYouTubeAPIExample:RetrievingUploadsbyChristinaPerricone(@hubspot)onCodePen. Go SeethePenYouTubeAPIExample:RetrievingUploads(Go)byChristinaPerricone(@hubspot)onCodePen. .NET SeethePenYouTubeAPIExample:RetrievingUploads(.NET)byChristinaPerricone(@hubspot)onCodePen. Ruby SeethePenYouTubeAPIExample:RetrievingUploads(Ruby)byChristinaPerricone(@hubspot)onCodePen. 2.RetrievingSearchResultsforaCertainKeyword YoucanusetheYouTubeAPItoretrievesearchresultsforacertainkeyword.Usethecodesamplesbelowtodoso. AppsScript SeethePenYouTubeAPIExample:Search(AppsScript)byChristinaPerricone(@hubspot)onCodePen. Go SeethePenYouTubeAPIExample:Search(Go)byChristinaPerricone(@hubspot)onCodePen. .NET SeethePenYouTubeAPIExample:Search(.NET)byChristinaPerricone(@hubspot)onCodePen. Ruby SeethePenYouTubeAPIExample:Search(Ruby)byChristinaPerricone(@hubspot)onCodePen. FormoreAppsScript,Go,.NET,andRubycodesamples,clickhere. CustomYouTubeAPICodeSamples Ifyou’reusingJava,JavaScript,PHP,Python,orcurltoconnectyourwebsiteorapptotheYouTubeAPI,clickheretoaccesscodesamplesyoucancustomize. Tocreateacodesampleforyourspecificusecase,takethefollowingsteps. Choosearesource.ThisreferstothedatayouwanttoretrieveusingtheAPI.Forexample,youcanchoose“channels,”“videos,”“playlists,”and“search.” Chooseamethodthatalignswithwhatyou’regenerallylookingtodo.For“videos,”forexample,youcanchoose“list,”“getRating,”or“insert.” Findtheusecasethatalignswithwhatyouspecificallywanttodo.Forinstance,afterchoosing“videos”asyourresourceand“list”asyourmethod,youcaneithergetacodesampleforlistingYouTube’smostpopularvideosorlistingyourlikedvideos. Clickthe>nexttotheusecase.Thiswillopenupa“TrythisAPI”windowwhereyoucancustomizetherequestparameters,suchasthevideoCategoryIdandregionCode. Afteryou’refinishedcustomizing,clickExecute.You’llbepromptedtologinandprovideaccesstotheAPIExplorer.You’llthenbetakenbacktothepreviouswindow,whereyourcodesnippethasbeengenerated. HowtoUsetheYouTubeAPIonYourWordPressWebsite Ifyou’renewtoAPIsanddon’tknowhowtouseitonyourwebsite,you’reinluck.It’srelativelysimpletodoevenifyoudon’thaveanyadvancedtechnicalknowledge. Oneofthemosteffectivewaystopromoteyourbusinessthroughvideomarketing,withoutcreatingthevideosyourself,istocurateYouTubecontent.WithsomuchcontentalreadybeingcreatedonYouTube(300hoursofvideoperminute),browsingontheplatformcangetoverwhelmingfortheuser. ImageSource UsingapluginandaYouTubeAPIkey,youcanstepinanddevelopstandalonecontentorlistsofvideosaboutspecificsubjectswithinyourindustry.ThiswillmakeiteasierforyouraudiencetodiscoverqualityYouTubecontentwhilepromotingthecontentcreatorforfree.Yourpaymentcomesaboutintheformofgrowingwebsitetraffic. Videoisalsoagreatwaytoillustrateyourpointswhenwritingblogposts.Itdeliversthemessagefaster,cancovermoredepth,andisthepreferredcontentconsumptionmethodformany. HerearesomeWordPressYouTubepluginsyoucanusetoengageyourvisitorsonyourWordPresswebsite.Foreachoftheseplugins,you’llneedaYouTubeAPIkey. 1.WonderPlugin WonderPluginletsyouembedaplaylistgalleryonyourwebsiteusingaYouTubeAPIkey.YoucanalsoembedYouTubecarousels. 2.VideographyWP VideographyWPisahandypluginthatallowsyoutoreplacefeaturedimageswithfeaturedvideos.AfteryouinputaYouTubeAPIkeyintotheplugin’ssettings,thepluginretrievesthevideoforyouwithoutyouneedingtocodeitintothethemeorpage. 3.AutomaticYouTubeGallery AutomaticYouTubeGalleryisasautomaticasitsounds.TocreateavideogalleryonyourWPwebsite,simplyinputthenameofthechannel,user,searchterm,orplaylistintotheplugin’ssettings.You’llneedaYouTubeAPIkeyforthisplugintoautomaticallyretrievethedata. 4.WPYouTubeLite WPYouTubeLiteallowsyoutoembedvideosonyoursitewithoutslowingdownyourpagespeed.UsingtheYouTubeAPI,itloadsYouTubevideosintoamuchlightervideoplayerthatwillkeepyourpage’sloadingtimefast. 5.FeedThemSocial TheFeedThemSocialpluginallowsyoutocreateandembedsocialmediafeedsonyourwebsite.ItinterfaceswiththeYouTubeAPItoretrieveallofYouTube’sdataandcreateacustomfeed.ToactivateaYouTubefeed,you’llnavigatetotheYouTubeOptionspageonyourpluginsettingsandenteryourAPIkey. YouTubeAPIFAQs StillhavequestionsaboutusingtheYouTubeAPI?Wehaveanswersbelow. IstheYouTubeAPIFree? TheYouTubeAPIisfreeifyoudon’texceedyourdailyAPIrequestquota.Eachrequestcostsapredeterminedamountofpoints.Youget10,000pointsperday. HowMuchDoestheYouTubeAPICost? ThechargeforaccessingtheYouTubeDataAPIisbasedonquotausage.Foreachproject,you'regiven10,000freepointsperdayandallrequestscostatleastonepoint. ImageSource YoucanestimateyourquotacostsusingtheQuotaCalculator,andifyouneedmorequeries,youcanapplyforhigherquotas.Thepricingmaynotremainthesame. UsetheYouTubeAPItoGrowBetter YouTubecanhelpyoureachalargeraudienceandgrowyourcustomerbase.Ithasanestablisheduserbase,providingtheperfectenvironmentforbusinesses,marketers,creatives,andvirtuallyanyonewhowantstoreachthepublictodosoeasily. Consistentlycreatinghighquality,originalcontentcanbedifficulttoincorporateintomostmarketingstrategies.ButwithaccesstotheYouTubeDataAPI,youcantakethesecond-bestroutetouseYouTubeformarketing:sharingvideoonyourwebsite. Editor'snote:ThispostwasoriginallypublishedinMarch2020andhasbeenupdatedforcomprehensiveness.   OriginallypublishedMar22,20227:00:00AM,updatedApril202022 Topics: ApplicationProgrammingInterface(API) Don'tforgettosharethispost! RelatedArticles WhatIsaRetailAPI?13BestExamples Website  |11minread Looking foranEcommerceAPI?HereAre18ofOurFavorites Website  |9minread 10BestAPIDocumentationToolsfor2022[+WhyUseOne] Website  |7minread ExpandOffer SignupforHubSpot'sCMSSoftware Getitnow Getitnow DownloadforLater



請為這篇文章評分?