0
Ruby on Rails 앱을 사용하여 Google 문서를 만들거나 보려고합니다. 문서를 만들 수 있다고 생각하지만 API 콜백에서 가져온 링크를 클릭하면 401 오류가 발생합니다. 로그인 필요.Google 드라이브의 서비스 계정에 로그인해야합니다.
다음은 문서 작성 코드입니다.
key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'notasecret')
asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL,
'https://www.googleapis.com/auth/drive', key)
client = Google::APIClient.new
client.authorization = asserter.authorize()
drive = client.discovered_api('drive', 'v2')
puts 'hello'
file = drive.files.insert.request_schema.new({
'title' => 'My document',
'description' => 'A test document',
'mimeType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
})
puts 'world'
media = Google::APIClient::UploadIO.new(Rails.root.to_s + '/app/assets/documents/document.doc', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
result = client.execute(
:api_method => drive.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'multipart',
'alt' => 'json'}
)
puts '==========='
puts result
puts '==========='
jj result.data.to_hash
의견이 있으십니까?
감사합니다.
Google 드라이브 젬이 있는데 여기에서 볼 수있는 것에서 사용하기가 훨씬 쉬워 보입니다. – three
이 보석을 사용하여 Google 문서에 대한 링크를 얻는 방법이 있습니까? – babaloo
네, 생각해보십시오. https://github.com/gimite/google-drive-ruby 스프레드 시트에 사용하고 있으며 간단합니다. – three