Sample code for 30+ languages & platforms
Xbase++

Paging User Photos with Cursor

See more Facebook Examples

Demonstrates how to iterate over the pages of user photos using a cursor.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oOauth2
LOCAL oRest
LOCAL cResponseJson
LOCAL oJson
LOCAL cAfterCursor

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.
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)

//  Indicate that we only want the photos the user has personally uploaded.
oRest:AddQueryParam("type", "uploaded")

//  We could limit the number of photos per page using the "limit" field.
oRest:AddQueryParam("limit", "20")

//  Get the 1st page of photos. (Not the actual image data, but the information about each photo.)
//  See https://developers.facebook.com/docs/graph-api/reference/user/photos/ for more information.
cResponseJson := oRest:FullRequestNoBody("GET", "/v2.7/me/photos")
IF (oRest:LastMethodSuccess != 1)
    ? oRest:LastErrorText
    oOauth2:destroy()
    oRest:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
oJson:Load(cResponseJson)
? oJson:Emit()

//  See Parsing the Facebook User Photos for code showing how to parse the JSON photos content.
//  

//  Get the "after" cursor.
cAfterCursor := oJson:StringOf("paging.cursors.after")
DO WHILE oJson:LastMethodSuccess == 1

    ? "after cursor: " + cAfterCursor

    //  Prepare for getting the next page of photos.
    //  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:AddQueryParam("type", "uploaded")
    oRest:AddQueryParam("limit", "20")
    oRest:AddQueryParam("after", cAfterCursor)

    cResponseJson := oRest:FullRequestNoBody("GET", "/v2.7/me/photos")
    IF (oRest:LastMethodSuccess != 1)
        ? oRest:LastErrorText
        oOauth2:destroy()
        oRest:destroy()
        oJson:destroy()
        RETURN
    ENDIF

    oJson:Load(cResponseJson)
    //  See Parsing the Facebook User Photos for code showing how to parse the JSON photos content.

    ? oJson:Emit()

    //  Get the cursor for the next page.
    cAfterCursor := oJson:StringOf("paging.cursors.after")
ENDDO

? "No more pages of photos."

oOauth2:destroy()
oRest:destroy()
oJson:destroy()