Sample code for 30+ languages & platforms
DataFlex

Get the Photos for a User

See more Facebook Examples

Demonstrates how to get the photos that the user has uploaded.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vOauth2
    Handle hoOauth2
    Handle hoRest
    String sResponseJson
    Handle hoJson
    Handle hoDtime
    Boolean iBLocalTime
    Variant vDt
    Handle hoDt
    Integer i
    Integer iNumItems
    String sName
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Integer iTemp3
    Integer iTemp4
    Integer iTemp5
    Boolean bTemp1

    Move False To iSuccess

    // 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
    Get Create (RefClass(cComChilkatOAuth2)) To hoOauth2
    If (Not(IsComObjectCreated(hoOauth2))) Begin
        Send CreateComObject of hoOauth2
    End
    Set ComAccessToken Of hoOauth2 To "FACEBOOK-ACCESS-TOKEN"

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    // Connect to Facebook.
    Get ComConnect Of hoRest "graph.facebook.com" 443 True True To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Provide the authentication credentials (i.e. the access key)
    Get pvComObject of hoOauth2 to vOauth2
    Get ComSetAuthOAuth2 Of hoRest vOauth2 To iSuccess

    // Indicate that we only want the photos the user has personally uploaded.
    Get ComAddQueryParam Of hoRest "type" "uploaded" To iSuccess

    // We could limit the number of photos by setting a limit.
    Get ComAddQueryParam Of hoRest "limit" "5" To iSuccess

    // Gets 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.
    Get ComFullRequestNoBody Of hoRest "GET" "/v2.7/me/photos" To sResponseJson
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Set ComEmitCompact Of hoJson To False
    Get ComLoad Of hoJson sResponseJson To iSuccess
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    // A sample JSON response is shown below.  
    // This is the code to parse the JSON response.

    Get Create (RefClass(cComCkDateTime)) To hoDtime
    If (Not(IsComObjectCreated(hoDtime))) Begin
        Send CreateComObject of hoDtime
    End
    Move True To iBLocalTime

    Get Create (RefClass(cComChilkatDtObj)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End
    Move 0 To i
    Get ComSizeOfArray Of hoJson "data" To iNumItems
    While (i < iNumItems)
        Set ComI Of hoJson To i
        Showln "--- " i
        Get ComStringOf Of hoJson "data[i].name" To sName
        Get ComLastMethodSuccess Of hoJson To bTemp1
        If (bTemp1 = True) Begin
            Showln "name: " sName
        End

        Get ComStringOf Of hoJson "data[i].id" To sTemp1
        Showln "id: " sTemp1

        // We can load the created_time into a CkDateTime...
        Get ComStringOf Of hoJson "data[i].created_time" To sTemp1
        Get ComSetFromTimestamp Of hoDtime sTemp1 To iSuccess
        Get pvComObject of hoDt to vDt
        Send ComToDtObj To hoDtime iBLocalTime vDt

        Get ComMonth Of hoDt To iTemp1
        Get ComDay Of hoDt To iTemp2
        Get ComYear Of hoDt To iTemp3
        Get ComHour Of hoDt To iTemp4
        Get ComMinute Of hoDt To iTemp5
        Showln iTemp1 "/" iTemp2 "/" iTemp3 "  " iTemp4 ":" iTemp5
        Move (i + 1) To i
    Loop

    // We can get the paging information as follows:
    Get ComStringOf Of hoJson "paging.next" To sTemp1
    Showln "URL for next page: " sTemp1
    Get ComStringOf Of hoJson "paging.cursors.before" To sTemp1
    Showln "before cursor: " sTemp1
    Get ComStringOf Of hoJson "paging.cursors.after" To sTemp1
    Showln "after cursor: " sTemp1

    // This is a sample JSON response:
    // { 
    //   "data": [
    //     {
    //       "created_time": "2016-09-29T20:46:18+0000",
    //       "name": "Ignore my posts -- I'm doing some testing for Facebook related programming...",
    //       "id": "10210199026347451"
    //     },
    //     { 
    //       "created_time": "2016-09-19T02:00:42+0000",
    //       "id": "10210091531240138"
    //     },
    //     { 
    //       "created_time": "2016-09-19T02:00:42+0000",
    //       "id": "10210091520620125"
    //     },
    //     { 
    //       "created_time": "2016-09-19T01:59:46+0000",
    //       "name": "I would've went for a swim had it not been for the sign",
    //       "id": "10210091522299917"
    //     },
    //     { 
    //       "created_time": "2016-09-12T00:37:35+0000",
    //       "id": "10210023316834798"
    //     }
    //   ],
    //   "paging": { 
    //     "cursors": { 
    //       "before": "MTAyMTAxOTkwMjYzNDc0NTEZD",
    //       "after": "MTAyMTAwMjMzMTU4MzQ3OTgZD"
    //     },
    //     "next": "https:\/\/graph.facebook.com\/v2.7\/10224048320139890\/photos?type=uploaded&limit=5&after=MTAyMTAwMjMzMTU4MzQ3OTgZD"
    //   }
    // }
    // 


End_Procedure