Lua
Lua
Iterate Pages in Feed
See more Facebook Examples
Demonstrates how to read the next page in the user's Facebook feed, and iterates through all of the pages in the Facebook feed.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.
-- This example assumes a previously obtained an access token
local oauth2 = chilkat.OAuth2.new()
oauth2.access_token = "FACEBOOK-ACCESS-TOKEN"
local rest = chilkat.Rest.new()
-- Connect to Facebook and send the following GET request:
local success = rest:connect("graph.facebook.com", 443, true, true)
if not success then
print(rest.last_error_text)
return
end
-- Provide the authentication credentials (i.e. the access key)
rest:set_auth_oauth2(oauth2)
-- Gets the 1st page in the user's feed.
local responseJson = rest:full_request_no_body("GET", "/v2.7/me/feed")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
local json = chilkat.JsonObject.new()
json.emit_compact = false
json:load(responseJson)
-- See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
--
local nextUrl = chilkat.Url.new()
-- Get the URL for the next page in the feed.
local nextUrlStr = json:string_of("paging.next")
while json.last_method_success do
print("Next page URL: " .. nextUrlStr)
nextUrl:parse_url(nextUrlStr)
-- Prepare for getting the next page in the feed.
-- We can continue using the same REST object.
-- If already connected, we'll continue using the existing connection.
-- Otherwise, a new connection will automatically be made if needed.
rest:clear_all_query_params()
rest:add_query_params(nextUrl.query)
responseJson = rest:full_request_no_body("GET", "/v2.7/me/feed")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
json:load(responseJson)
-- See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
-- Get the URL for the next page.
nextUrlStr = json:string_of("paging.next")
end
print("No more pages in the feed.")