https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps
get 요청
유저가 권한을 부여하면 code를 얻음
https://accounts.google.com/o/oauth2/v2/auth?
redirect_uri={callbackUrl} &
response_type=code &
client_id={client_id} &
scope=https://www.googleapis.com/auth/youtube.readonly &
access_type=offline
<client_id 및 client_secret>
response
http://example.com/example_directory/?
code=4%2FjD21vE3nIwsCjBDH-DbXRxugvLHgaQC-rBJ1oNi8sHk#
post 요청
첫 연동 시에만 하면 됨
https://accounts.google.com/o/oauth2/token?
code={code} &
client_id={client_id} &
client_secret={client_secret} &
redirect_uri={redirect_uri} &
grant_type="authorization_code"
<redirect_uri>
response
{
"access_token" : "ya29.GltZBSkIf23G21usdyOab5i83wuDDhg5eisiY--9tl_x2AHjm-9wX-aHMh6xbhRjhiGwqLjwROSqkouHmgWtKivWj35iGob_fjCjdLSs9IjM-IfP_T9Xb6UP-tHQ",
"expires_in" : 3600,
"refresh_token" : "1/BvBCGUfg-fdkse6dR-cdGiaR_V-SLiDQaYM3omHkS4o",
"token_type" : "Bearer"
}
{
"access_token" : "ya29.GltZBVsB8M9UVg_4l7JzCjtUFNCxcEKzIj2c4QsVAzoC_-CCIqypak3NJ95iNAtUy2sOM2gY9h_68xi2SBG7cPb3Ygi9al2E8chtDWfVaOGL_-1v5jizn4Rk3o4T",
"expires_in" : 3598,
"token_type" : "Bearer"
}
https://www.googleapis.com/oauth2/v1/tokeninfo?
access_token={access_token}
response
{
"error": "invalid_token",
"error_description": "Invalid Value"
}
{
"issued_to": "245-cgqtpdgcnt5n6o8.apps.googleusercontent.com",
"audience": "245-cgqtpdgcnt5n6o8.apps.googleusercontent.com",
"scope": "https://www.googleapis.com/auth/youtube.readonly",
"expires_in": 3553,
"access_type": "offline"
}
https://accounts.google.com/o/oauth2/token?
client_id={client_id} &
client_secret={client_secret} &
refresh_token={refresh_token} &
grant_type="refresh_token"
response
{
"error" : "invalid_request",
"error_description" : "Missing required parameter: refresh_token"
}
{
"access_token" : "ya29.GltZBcG0ko1w91KFzP8_W4PV1vYUWTCBGG0FhGdIxTHSlP7yyhUPG6b8f3djbJOTGwfSMaf_WyMpPDRG6u3QR4i20JpFAYGfJxeNATuO39EqjOU_sM2vSDqWZrnt",
"expires_in" : 3600,
"token_type" : "Bearer"
}
https://www.googleapis.com/youtube/v3/channels?
access_token={access_token}&
part="snippet,statistics"&
mine=true
response
{
"kind": "youtube#channelListResponse",
"etag": "",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "",
"id": "",
"snippet": {
"title": "title example",
"description": "",
"publishedAt": "2018-01-25T06:48:28.000Z",
"thumbnails": {
"default": {
"url": "https://asdf/photo.jpg"
},
"medium": {
"url": "https://asdf/photo.jpg"
},
"high": {
"url": "https://asdf/photo.jpg"
}
},
"localized": {
"title": "example title",
"description": ""
}
},
"statistics": {
"viewCount": "3",
"commentCount": "0",
"subscriberCount": "0",
"hiddenSubscriberCount": false,
"videoCount": "1"
}
}
]
}
https://www.googleapis.com/youtube/v3/search?
access_token={access_token} &
part="id" &
q="검색할 단어나 태그" &
forMine="true" &
type="video"
response
{
"kind": "youtube#searchListResponse",
"etag": "",
"nextPageToken": "Cib3-nqn8_____9rVDdjNnlyc3dXcwD_Af_-a1Q3YzZ5cnN3MAARABIa5I5Tvd3y-QOQAAAAAMWIUFSAFQAloLCV6DRi3vNm3vEAJg_eGT3AE=",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"Wu2llbfqCdx/_dujpjJb23VH\"",
"id": {
"kind": "youtube#video",
"videoId": "kT7rsw"
}
}
]
}
https://www.googleapis.com/youtube/v3/videos?
access_token={access_token} &
part="id,snippet,contentDetails,fileDetails,liveStreamingDetails,player,processingDetails,recordingDetails,statistics,status,suggestions,topicDetails" &
id={videoId}
response
{
"kind": "youtube#videoListResponse",
"etag": "\"Wu2llbfqCdxCA/lrPm-K0\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"Wu2llbfqPCA/cjjlCIuXr\"",
"id": "kT7c6yrswWs",
"snippet": {
"publishedAt": "2018-01-25T06:51:38.000Z",
"channelId": "UC0qwTvoNkbE2EGVhYhNpC",
"title": "bali",
"description": "example description",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/kT7c6yrsw/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/kT7c6yrsw/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/kT7c6yrsw/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/kT7c6yrsw/sddefault.jpg",
"width": 640,
"height": 480
}
},
"channelTitle": "maggie's channel",
"tags": [
"#maggie #blahblah #example"
],
"categoryId": "22",
"liveBroadcastContent": "none",
"localized": {
"title": "bali",
"description": "example description"
}
},
"contentDetails": {
"duration": "PT5S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": false,
"projection": "rectangular",
"hasCustomThumbnail": false
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
},
"statistics": {
"viewCount": "3",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"player": {
"embedHtml": "\u003ciframe width=\"480\" height=\"360\" src=\"//www.youtube.com/embed/kT7c6yrsw\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen\u003e\u003c/iframe\u003e"
},
"recordingDetails": {
"location": {
"altitude": 0.0
}
},
"fileDetails": {
"fileName": ""
},
"processingDetails": {
"processingStatus": "terminated"
}
}
]
}