•  


Add file for coming-soon Ruby quickstart guide. · youtube/api-samples@53c6d50 · GitHub
Skip to content

Commit

Permalink
Add file for coming-soon Ruby quickstart guide.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyDiamondstein committed Apr 24, 2017
1 parent 55bf401 commit 53c6d50
Showing 1 changed file with 64 additions and 0 deletions .
64 changes: 64 additions & 0 deletions ruby/quickstart.rb
@@ -0,0 +1,64 @@
# Sample Ruby code for user authorization

require 'rubygems'
gem 'google-api-client' , '>0.7'
require 'google/apis'
require 'google/apis/youtube_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'

require 'fileutils'
require 'json'

# REPLACE WITH VALID REDIRECT_URI FOR YOUR CLIENT
REDIRECT_URI = 'http://localhost'
APPLICATION_NAME = 'YouTube Data API Ruby Tests'

# REPLACE WITH NAME/LOCATION OF YOUR client_secrets.json FILE
CLIENT_SECRETS_PATH = 'client_secret.json'

# REPLACE FINAL ARGUMENT WITH FILE WHERE CREDENTIALS WILL BE STORED
CREDENTIALS_PATH = File . join ( Dir . home , '.credentials' ,
"youtube-quickstart-ruby-credentials.yaml" )

# SCOPE FOR WHICH THIS SCRIPT REQUESTS AUTHORIZATION
SCOPE = Google :: Apis :: YoutubeV3 :: AUTH_YOUTUBE_READONLY

def authorize
FileUtils . mkdir_p ( File . dirname ( CREDENTIALS_PATH ) )

client_id = Google :: Auth :: ClientId . from_file ( CLIENT_SECRETS_PATH )
token_store = Google :: Auth :: Stores :: FileTokenStore . new ( file : CREDENTIALS_PATH )
authorizer = Google :: Auth :: UserAuthorizer . new (
client_id , SCOPE , token_store )
user_id = 'default'
credentials = authorizer . get_credentials ( user_id )
if credentials . nil?
url = authorizer . get_authorization_url ( base_url : REDIRECT_URI )
puts "Open the following URL in the browser and enter the " +
"resulting code after authorization"
puts url
code = gets
credentials = authorizer . get_and_store_credentials_from_code (
user_id : user_id , code : code , base_url : REDIRECT_URI )
end
credentials
end

# Initialize the API
service = Google :: Apis :: YoutubeV3 :: YouTubeService . new
service . client_options . application_name = APPLICATION_NAME
service . authorization = authorize

# Sample ruby code for channels.list

def channels_list_by_username ( service , part , ** params )
response = service . list_channels ( part , params ) . to_json
item = JSON . parse ( response ) . fetch ( "items" ) [ 0 ]

puts ( "This channel's ID is #{ item . fetch ( "id" ) } . " +
"Its title is ' #{ item . fetch ( "snippet" ) . fetch ( "title" ) } ', and it has " +
" #{ item . fetch ( "statistics" ) . fetch ( "viewCount" ) } views." )
end

channels_list_by_username ( service , 'snippet,contentDetails,statistics' , for_username : 'GoogleDevelopers' )

1 comment on commit 53c6d50

@vicluk
Copy link

Choose a reason for hiding this comment

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

`

REEMPLAZAR CON REDIRECT_URI VALIDO PARA SU CLIENTE

REDIRECT_URI = ' http://localhost '
APPLICATION_NAME = 'Pruebas Ruby de la API de datos de YouTube'

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