Sample code for 30+ languages & platforms
DataFlex

Facebook User Feed (Read Posts)

See more Facebook Examples

Demonstrates how to read the feed of posts (including status updates) and links published by this person, or by others on this person's profile. This introductory example gets the first few posts.

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 sMessage
    String sStory
    String sPrevUrl
    String sNextUrl
    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 and send the following GET request:
    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

    // We could limit the number of posts.  The default limit is 25.
    Get ComAddQueryParam Of hoRest "limit" "5" To iSuccess

    Get ComFullRequestNoBody Of hoRest "GET" "/v2.7/me/feed" 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

    // Show the JSON in human-readable format.
    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].message" To sMessage
        Get ComLastMethodSuccess Of hoJson To bTemp1
        If (bTemp1 = True) Begin
            Showln "message: " sMessage
        End

        Get ComStringOf Of hoJson "data[i].story" To sStory
        Get ComLastMethodSuccess Of hoJson To bTemp1
        If (bTemp1 = True) Begin
            Showln "story: " sStory
        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

    // Finally, there are two paging URLs at the very bottom.  Those can be accessed as shown:
    Get ComStringOf Of hoJson "paging.previous" To sPrevUrl
    Showln "URL for previous page: " sPrevUrl

    Get ComStringOf Of hoJson "paging.next" To sNextUrl
    Showln "URL for next page: " sNextUrl

    // -------------------------------------------------------------------
    // This is a sample JSON response..
    // { 
    //   "data": [
    //     { 
    //       "message": "This is the first post.",
    //       "created_time": "2016-09-28T14:36:45+0000",
    //       "id": "12345678901234567_12345678900000001"
    //     },
    //     { 
    //       "message": "This is the 2nd post.",
    //       "created_time": "2016-09-27T03:26:12+0000",
    //       "id": "12345678901234567_12345678900000002"
    //     },
    //     { 
    //       "story": "John Doe shared Mary's post.",
    //       "created_time": "2016-09-26T15:45:10+0000",
    //       "id": "12345678901234567_12345678900000003"
    //     },
    //     { 
    //       "message": "https:\/\/www.somewebsite.org\/?ID=8158",
    //       "created_time": "2016-09-26T02:29:20+0000",
    //       "id": "12345678901234567_12345678900000004"
    //     },
    //     { 
    //       "message": "http:\/\/blog.somebody.com\/post\/123",
    //       "created_time": "2016-09-26T02:02:56+0000",
    //       "id": "12345678901234567_12345678900000005"
    //     },
    //     { 
    //       "story": "John Doe shared Bill's photo.",
    //       "created_time": "2016-09-25T15:32:09+0000",
    //       "id": "12345678901234567_12345678900000006"
    //     },
    //     { 
    //       "message": "Check this out...",
    //       "story": "John Doe shared NPR Music's video.",
    //       "created_time": "2016-09-25T14:54:52+0000",
    //       "id": "12345678901234567_12345678900000007"
    //     },
    //     { 
    //       "message": "Yet another post...",
    //       "created_time": "2016-09-24T17:21:30+0000",
    //       "id": "12345678901234567_12345678900000008"
    //     },
    //     { 
    //       "message": "http:\/\/www.somewhere.com\/blahblahblah\/",
    //       "created_time": "2016-09-23T22:20:29+0000",
    //       "id": "12345678901234567_12345678900000009"
    //     },
    //     { 
    //       "message": "At Lincoln marsh ...",
    //       "story": "John Doe added 2 new photos.",
    //       "created_time": "2016-09-19T02:00:43+0000",
    //       "id": "12345678901234567_12345678900000010"
    //     },
    //     { 
    //       "message": "I would've went for a swim had it not been for the sign",
    //       "created_time": "2016-09-19T01:59:47+0000",
    //       "id": "12345678901234567_12345678900000011"
    //     },
    //     { 
    //       "story": "John Doe shared Steve's video.",
    //       "created_time": "2016-09-17T22:00:02+0000",
    //       "id": "12345678901234567_12345678900000012"
    //     },
    //     { 
    //       "message": "Another sample message...",
    //       "story": "John Doe shared XYZ's post.",
    //       "created_time": "2016-09-17T14:13:16+0000",
    //       "id": "12345678901234567_12345678900000013"
    //     },
    //     { 
    //       "message": "Hello World!",
    //       "created_time": "2016-09-16T23:17:13+0000",
    //       "id": "12345678901234567_12345678900000014"
    //     },
    //     { 
    //       "message": "https:\/\/www.youtube.com\/watch?v=xyz",
    //       "created_time": "2016-09-15T04:13:02+0000",
    //       "id": "12345678901234567_12345678900000015"
    //     },
    //     { 
    //       "story": "John Doe shared Emily's photo.",
    //       "created_time": "2016-09-14T16:37:10+0000",
    //       "id": "12345678901234567_12345678900000016"
    //     },
    //     { 
    //       "story": "John Doe shared Vincent's photo.",
    //       "created_time": "2016-09-14T14:03:42+0000",
    //       "id": "12345678901234567_12345678900000017"
    //     },
    //     { 
    //       "message": "https:\/\/www.chilkatsoft.com\/",
    //       "created_time": "2016-09-14T02:29:37+0000",
    //       "id": "12345678901234567_12345678900000018"
    //     },
    //     { 
    //       "message": "So cool!  Marcus jamming with this 16 year old kid...",
    //       "created_time": "2016-09-13T17:04:53+0000",
    //       "id": "12345678901234567_12345678900000019"
    //     },
    //     { 
    //       "message": "Wow!",
    //       "story": "John Doe shared Somebody's post.",
    //       "created_time": "2016-09-13T14:11:18+0000",
    //       "id": "12345678901234567_12345678900000020"
    //     }
    //   ],
    //   "paging": { 
    //     "previous": "https:\/\/graph.facebook.com\/v2.7\/12345678901234567\/feed?since=1475073405&limit=25&__paging_token=enc_abcT9x9GFabcTxvnyXZC0xnHZCrH2h4yjNZCZAUabcZAI9TyZBibwat6wCYiSFTxR4nSDZAkzaN8vIaEPmqrabc1QTIbGac&__previous=1",
    //     "next": "https:\/\/graph.facebook.com\/v2.7\/12345678901234567\/feed?limit=25&until=1473426350&__paging_token=enc_AdDFWabcYtV5ob6lFO8LZAMhm7LKCxntawqqabcZALyC8WZB8Th2lON7HGuJRabzW6Ivfm93LORIw9NNBuHpob7abcjh"
    //   }
    // }
    // 


End_Procedure