Lua
Lua
Create Google Photos Album
See more Google Photos Examples
Demonstrates how to create a Google Photos album.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- Get the previously obtained access token.
-- See Get Google Photos Access Token.
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/googlePhotos.json")
if not success then
print(jsonToken.last_error_text)
return
end
local http = chilkat.Http.new()
http.auth_token = jsonToken:string_of("access_token")
-- Create an album named "animals"
local json = chilkat.JsonObject.new()
json:update_string("album.title", "animals")
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://photoslibrary.googleapis.com/v1/albums", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
-- Show the response body.
print(resp.body_str)
-- Examine the response status code. Success is indicated by a status code of 200.
print("response status code: " .. resp.status_code)
json:load(resp.body_str)
-- Sample response:
-- {
-- "id": "AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
-- "title": "animals",
-- "productUrl": "https://photos.google.com/lr/album/AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
-- "isWriteable": true
-- }
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
local id = json:string_of("id")
local title = json:string_of("title")
local productUrl = json:string_of("productUrl")
local isWriteable = json:bool_of("isWriteable")
print("id = " .. id)