•  


Add JS sample for calling YT Analytics API (v2) · youtube/api-samples@cdf1f87 · GitHub
Skip to content

Commit

Permalink
Add JS sample for calling YT Analytics API (v2)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyDiamondstein committed Apr 26, 2018
1 parent 53a12c0 commit cdf1f87
Showing 1 changed file with 35 additions and 0 deletions .
35 changes: 35 additions & 0 deletions javascript/yt_analytics_v2.html
@@ -0,0 +1,35 @@
< script src =" https://apis.google.com/js/api.js " > </ script >
< script >
function authenticate ( ) {
return gapi . auth2 . getAuthInstance ( )
. signIn ( { scope : "https://www.googleapis.com/auth/yt-analytics.readonly" } )
. then ( function ( ) { console . log ( "Sign-in successful" ) ; } ,
function ( err ) { console . error ( "Error signing in" , err ) ; } ) ;
}
function loadClient ( ) {
return gapi . client . load ( "https://youtubeanalytics.googleapis.com/$discovery/rest?version=v2" )
. then ( function ( ) { console . log ( "GAPI client loaded for API" ) ; } ,
function ( err ) { console . error ( "Error loading GAPI client for API" , err ) ; } ) ;
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute ( ) {
return gapi . client . youtubeAnalytics . reports . query ( {
"ids" : "channel==MINE" ,
"startDate" : "2017-01-01" ,
"endDate" : "2017-12-31" ,
"metrics" : "views,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,subscribersGained" ,
"dimensions" : "day" ,
"sort" : "day"
} )
. then ( function ( response ) {
// Handle the results here (response.result has the parsed body).
console . log ( "Response" , response ) ;
} ,
function ( err ) { console . error ( "Execute error" , err ) ; } ) ;
}
gapi . load ( "client:auth2" , function ( ) {
gapi . auth2 . init ( { client_id : 'YOUR_CLIENT_ID' } ) ;
} ) ;
</ script >
< button onclick =" authenticate().then(loadClient) " > authorize and load </ button >
< button onclick =" execute() " > execute </ button >

1 comment on commit cdf1f87

@km5464x
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more .

like it

did you manage to get the code working?

Please sign in to comment.
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본