Created
February 6, 2016 03:45
-
-
Save rinx/cdc5abb618e17b48529d to your computer and use it in GitHub Desktop.
flashair to google drive
This file contains hidden or 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
local cjson = require "cjson" | |
-- Basic account info | |
local client_id = "" | |
local client_secret = "" | |
local refresh_token = "" | |
local function getAuth() | |
local mes="client_id="..client_id | |
mes=mes.."&client_secret="..client_secret | |
mes=mes.."&refresh_token="..refresh_token | |
mes=mes.."&grant_type=refresh_token" | |
local length = string.len(mes) | |
print("Sending: ["..mes.."]") | |
print "\n" | |
b, c, h = fa.request{ | |
url = "https://accounts.google.com/o/oauth2/token", | |
headers = { | |
["Content-Type"] = "application/x-www-form-urlencoded", | |
["Content-Length"] = length, | |
}, | |
method = "POST", | |
body=mes, | |
} | |
print("sended, header:"..h.."\n") | |
local tempTable = {} | |
tempTable = cjson.decode(b) | |
local access_token = tempTable["access_token"] | |
print("access_token:"..access_token.."\n") | |
return (access_token) | |
end | |
local function uploadTest(token) | |
filePath="/testfile.jpg" | |
local fileSize = lfs.attributes(filePath,"size") | |
print("sending:"..filePath.."\n") | |
b, c, h = fa.request{ | |
url = "https://www.googleapis.com/upload/drive/v2/files", | |
headers = { | |
["Content-Type"] = "image/jpeg", | |
["Content-Length"] = fileSize, | |
["authorization"] = "Bearer "..token, | |
["uploadType"]="media" | |
}, | |
method = "POST", | |
file=filePath | |
} | |
print("sended:"..filePath.."\n") | |
end | |
access_token = getAuth() | |
uploadTest(access_token) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment