Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oOauth2
LOCAL oRest
LOCAL cResponseJson
LOCAL oJson
LOCAL oNextUrl
LOCAL cNextUrlStr
nSuccess := 0
// 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
oOauth2 := CreateObject("Chilkat.OAuth2")
oOauth2:AccessToken := "FACEBOOK-ACCESS-TOKEN"
oRest := CreateObject("Chilkat.Rest")
// Connect to Facebook and send the following GET request:
nSuccess := oRest:Connect("graph.facebook.com", 443, 1, 1)
IF (nSuccess != 1)
? oRest:LastErrorText
oOauth2:destroy()
oRest:destroy()
RETURN
ENDIF
// Provide the authentication credentials (i.e. the access key)
oRest:SetAuthOAuth2(oOauth2)
// Gets the 1st page in the user's feed.
cResponseJson := oRest:FullRequestNoBody("GET", "/v2.7/me/feed")
IF (oRest:LastMethodSuccess != 1)
? oRest:LastErrorText
oOauth2:destroy()
oRest:destroy()
RETURN
ENDIF
oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
oJson:Load(cResponseJson)
// See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
//
oNextUrl := CreateObject("Chilkat.Url")
// Get the URL for the next page in the feed.
cNextUrlStr := oJson:StringOf("paging.next")
DO WHILE oJson:LastMethodSuccess == 1
? "Next page URL: " + cNextUrlStr
oNextUrl:ParseUrl(cNextUrlStr)
// 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.
oRest:ClearAllQueryParams()
oRest:AddQueryParams(oNextUrl:Query)
cResponseJson := oRest:FullRequestNoBody("GET", "/v2.7/me/feed")
IF (oRest:LastMethodSuccess != 1)
? oRest:LastErrorText
oOauth2:destroy()
oRest:destroy()
oJson:destroy()
oNextUrl:destroy()
RETURN
ENDIF
oJson:Load(cResponseJson)
// See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
// Get the URL for the next page.
cNextUrlStr := oJson:StringOf("paging.next")
ENDDO
? "No more pages in the feed."
oOauth2:destroy()
oRest:destroy()
oJson:destroy()
oNextUrl:destroy()