Created
March 17, 2017 22:32
-
-
Save anonymous/f296d14e456a7c925d23a1282daa0b90 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfset variables.ytapikey = "insert API key here"> | |
<!--- I think this value is hidden from external users. Make certain of it, prior to live release ---> | |
<cfset variables.ytvidID = "insert videoID here" > | |
<!--- | |
The following code displays all the data available through this API method data for this specified (presumably, valid) videoID#. | |
<cfhttp method="get" url="https://www.googleapis.com/youtube/v3/videos?id=#variables.ytvidid#&key=#variables.ytapikey#&part=snippet" > | |
<cfdump var="#deserializeJSON(cfhttp.fileContent)#"> | |
Ideally, you would tweak that "&fields={ + value }" (below), specifying which data is needed. Why? To minimizing the limited data usage allotted to your API. | |
---> | |
<cfhttp method="get" url="https://www.googleapis.com/youtube/v3/videos?id=#variables.ytvidid#&key=#variables.ytapikey#&part=snippet&fields=items/snippet/title" > | |
<cfset getVidDetails = deserializeJSON(cfhttp.fileContent) /> | |
<cfif getVidDetails.error.code EQ "400" > | |
<p>Bad Request Error - The account set-up with the API key you specified has issues.</p> | |
<!--- cfdump var="#getVidDetails#"---> | |
<cfelseif arrayLen(getVidDetails.items) NEQ 1 > | |
<p>The specified videoID () is not valid.</p> | |
<cfelse> | |
<p>Title for www.youtube.com/watch/?v=#variables.ytvidID# = <strong>#getVidDetails.items[1].snippet.title#</strong></p> | |
</cfif> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment