--- This script will authenticate a user with google drive and print out
-- all available information about the files that they have stored.
-- Add your cliend ID and client secret below.

local loa=require "loa"
local authorization_endpoint = "https://accounts.google.com/o/oauth2/auth"
local token_endpoint         = "https://accounts.google.com/o/oauth2/token"
local resource_endpoint      = "https://www.googleapis.com/drive/v2"
local client_id              = "Your Client ID"
local client_secret          = "Your Client Secret"

local client=loa.new(authorization_endpoint, token_endpoint, resource_endpoint,
    client_id, client_secret)

local redirect_uri ="http://localhost:8081/"
local scope        ="https://www.googleapis.com/auth/drive.readonly.metadata"
local state        =nil -- Can be a string that will be returned by google
local default_query_parameters={key="value"}

local auth_uri=client:auth_uri(redirect_uri, scope, state,
    default_query_parameters)

--- Direct the user to the generated authorization URI
-- On Windows
os.execute(string.format('start %s', auth_uri:gsub("&",'^&')))
-- Unix-likes
-- os.execute(string.format("open '%s'", auth_uri))

-- Since we're not actually running a server we can use loa's _catch_redirect
-- function to get the http request being generated google.
local data=client._catch_redirect(redirect_uri)

-- Retrieve the code from the HTTP message we captured.
code=data:match('code=([^%s&]+)')

-- Request the token from google
client:request_token(nil, redirect_uri, {code=code})

for k,v in pairs(client) do print (k,v) end

-- Now you can make requests against your user account on google drive
local tbl=client:request("/files")

for k,v in pairs(tbl) do print(k,v) end
generated by LDoc 1.4.2