Google 드라이브에 파일을 보내는 간단한 애플리케이션 (Google 계정의 서비스 계정)을 만들고 싶습니다.Ruby를 사용하여 Google 드라이브 API에 대한 인증
것은 나는 다음과 같은 코드를 가지고 :
require 'rubygems'
require 'google/api_client'
require 'launchy'
#extra
gem 'oauth2'
gem 'omniauth'
client = Google::APIClient.new({:application_name => "testdevelop",:application_version => "1.0"})
drive = client.discovered_api('drive', 'v2')
####################################################################################
# Initialize OAuth 2.0 client
# client.authorization.client_id = '111062272758.apps.googleusercontent.com'
# client.authorization.client_secret = 's8j3VQwCvlyz2Hcpr06xrVfr'
# client.authorization.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
# client.authorization.scope = 'https://www.googleapis.com/auth/drive'
# uri = client.authorization.authorization_uri
# Launchy.open(uri)
# $stdout.write "Enter authorization code: "
# client.authorization.code = gets.chomp
# client.authorization.fetch_access_token!
####################################################################################
key = Google::APIClient::KeyUtils.load_from_pkcs12('12355eaee706eb725ff5dd890b5c2bc39d536a53-privatekey.p12', 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/prediction',
:issuer => '[email protected]account.com',
:signing_key => key)
client.authorization.fetch_access_token!
#####################################################################################
# Make an API call
# Insert a file
file = drive.files.insert.request_schema.new({
'title' => 'My document',
'description' => 'A test document',
'mimeType' => 'text/plain'
})
media = Google::APIClient::UploadIO.new('document.txt', 'text/plain')
result = client.execute(
:api_method => drive.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'multipart',
'alt' => 'json'})
# Pretty print the API result
jj result.data.to_hash
난 내가 ###### 라인 사이의 코드와 주석 코드를 주석의 주석을 해제 할 때 오류
`rescue in rbuf_fill': Timeout::Error (Faraday::Error::TimeoutError)
을 가지고 그것을 실행하는 경우 ######## gDrive에 파일을 보낼 수는 있지만 웹 브라우저에서 인증 코드를 입력해야합니다.
conn = Faraday.default_connection
conn.options[:timeout] = 500
및 당연히 연결 :
나는 내가 서비스
내가 추가 선으로 연결 시간을 증가시키기 위해 노력했다 계정과 같은 G 드라이브를 사용하기로 결정 먹으 렴를 automaticly을 수행 할 CONN를 한 후 매개 변수를 요청했지만 다른 오류가 있습니다.
`sysread_nonblock': end of file reached (Faraday::Error::ConnectionFailed)
이 링크는 질문에 대한 답변 일지 모르지만 여기에 대한 답변의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – theTRON
대답은 다음과 같습니다. "인증서 누락"- 나머지는 30자를 "가질"수있는 보너스입니다. – inselberg