Skip to content

Instantly share code, notes, and snippets.

@cigalecigales
Last active August 29, 2015 14:14
Show Gist options
  • Save cigalecigales/c918fbac1080b038f787 to your computer and use it in GitHub Desktop.
Save cigalecigales/c918fbac1080b038f787 to your computer and use it in GitHub Desktop.
[*Ruby*] RubyでGoogle Drive APIを使ってファイル一覧取得&ファイルアップロード ref: http://qiita.com/cigalecigales/items/470e81c78cf3ef350b0c
[クライアントID]
127036428910-2cihomq21p413jtu4ebmf4kvefi8v9p1.apps.googleusercontent.com
[クライアントシークレット]
2KR6kOI2hOs0QSKqqltrkyfi
[リダイレクトURI]
http://localhost
https://accounts.google.com/o/oauth2/auth
?client_id=クライアントID
&redirect_uri=リダイレクトURI
&scope=https://www.googleapis.com/auth/drive
&response_type=code
curl -d client_id=127036428910-2cihomq21p413jtu4ebmf4kvefi8v9p1.apps.googleusercontent.com -d client_secret=2KR6kOI2hOs0QSKqqltrkyfi -d refresh_token=1/djoROZFMLKPHygvCqtREUAnF7ddeG-3mtXagaXwXAUg -d grant_type=refresh_token https://accounts.google.com/o/oauth2/token
{
"access_token" : "ya29.DwHCrzGUsuzSUnFUKCHUugHXh3lTbYuBkn0fHk4lA33zxdGiFxT8palk5rvmR4PYlGqhlfFsRWzTBA",
"token_type" : "Bearer",
"expires_in" : 3600
}
$ gem install google_drive
$ ruby google-api-get-list.rb
IMG_0456.JPG
IMG_0454.JPG
IMG_0455.JPG
IMG_0451.JPG
(省略)
https://accounts.google.com/o/oauth2/auth
?client_id=127036428910-2cihomq21p413jtu4ebmf4kvefi8v9p1.apps.googleusercontent.com
&redirect_uri=http://localhost
&scope=https://www.googleapis.com/auth/drive
&response_type=code
http://localhost/?code=4/oIZC2ivBC4zV5subNiN6bou8uowe0Ix9L9TB5jDKUKs.IgN5uoclywkaBrG_bnfDxpI4cUOelgI
curl -d client_id=[クライアントID] -d client_secret=[クライアントシークレット] -d redirect_uri=[リダイレクトURI] -d grant_type=authorization_code -d code=[Authorization Code] https://accounts.google.com/o/oauth2/token
curl -d client_id=127036428910-2cihomq21p413jtu4ebmf4kvefi8v9p1.apps.googleusercontent.com -d client_secret=2KR6kOI2hOs0QSKqqltrkyfi -d redirect_uri=http://localhost -d grant_type=authorization_code -d code=4/oIZC2ivBC4zV5subNiN6bou8uowe0Ix9L9TB5jDKUKs.IgN5uoclywkaBrG_bnfDxpI4cUOelgI https://accounts.google.com/o/oauth2/token
{
"access_token" : "ya29.DwGisAjZTMSJH6biEjydYXIp6JaXRmYnh21CrW09XpSZzbyRtlg9xmONE1TD7tDDawQgpTjHgZD0kA",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/djoROZFMLKPHygvCqtREUAnF7ddeG-3mtXagaXwXAUg"
}
{
"error" : "invalid_grant"
}
{
"error" : "invalid_grant",
"error_description" : "Code was already redeemed."
}
curl -d client_id=[クライアントID] -d client_secret=[クライアントシークレット] -d refresh_token=[リフレッシュトークン] -d grant_type=refresh_token https://accounts.google.com/o/oauth2/token
file_name = "Test" + Time.now.strftime('%Y-%m-%d_%H:%M:%S') + ".txt"
file = File.open(file_name, 'w')
file.puts("Test Upload!!")
file.close
session.upload_from_file(file_name, file_name, :convert => false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment