Last active
August 29, 2015 13:56
-
-
Save ShogunPanda/9007021 to your computer and use it in GitHub Desktop.
Google Drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client = Google::APIClient.new(authorization: :oauth_2, application_name: NAME, application_version: VERSION) | |
client.client_id = CLIENT_ID | |
client.client_secret = CLIENT_SECRECT | |
client.authorization.scope = SCOPES | |
authorizer = Clavem::Authorizer.new do |auth, req, res| | |
raise RuntimeError.new if request.query["error"].present? || request.query["code"].blank? | |
client.authorization.code = request.query["code"].to_s | |
client.authorization.fetch_access_token! | |
client.authorization.refresh_token | |
end | |
client.authorization.redirect_uri = authorizer.callback_url | |
authorizer.authorize(client.authorization.authorization_uri) | |
if authorizer.succeeded? then | |
refresh_token = authorizer.token | |
end | |
# Now you can store the refresh token somewehere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client = Google::APIClient.new(authorization: :oauth_2, application_name: NAME, application_version: VERSION) | |
client.client_id = CLIENT_ID | |
client.client_secret = CLIENT_SECRECT | |
client.authorization.scope = SCOPES | |
client.authorization.code = REFRESH_TOKEN | |
client.authorization.fetch_access_token! | |
api = client.discovered_api('drive', 'v2') | |
data = client.execute(api_method: api.files.get, parameters: {"fileId" => ID}) | |
raise ArgumentError if result.status == 404 | |
url = result.data.alternate_link | |
# Now you can download from URL using Faraday, open-uri or whatever. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment