Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Iterate Pages in FeedDemonstrates how to read the next page in the user's Facebook feed, and iterates through all of the pages in the Facebook feed.
IncludeFile "CkUrl.pb" IncludeFile "CkRest.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkOAuth2.pb" Procedure ChilkatExample() ; 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 oauth2.i = CkOAuth2::ckCreate() If oauth2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkOAuth2::setCkAccessToken(oauth2, "FACEBOOK-ACCESS-TOKEN") rest.i = CkRest::ckCreate() If rest.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to Facebook and send the following GET request: success.i = CkRest::ckConnect(rest,"graph.facebook.com",443,1,1) If success <> 1 Debug CkRest::ckLastErrorText(rest) CkOAuth2::ckDispose(oauth2) CkRest::ckDispose(rest) ProcedureReturn EndIf ; Provide the authentication credentials (i.e. the access key) CkRest::ckSetAuthOAuth2(rest,oauth2) ; Gets the 1st page in the user's feed. responseJson.s = CkRest::ckFullRequestNoBody(rest,"GET","/v2.7/me/feed") If CkRest::ckLastMethodSuccess(rest) <> 1 Debug CkRest::ckLastErrorText(rest) CkOAuth2::ckDispose(oauth2) CkRest::ckDispose(rest) ProcedureReturn EndIf json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::setCkEmitCompact(json, 0) CkJsonObject::ckLoad(json,responseJson) ; ; See Parsing the Facebook User Feed for code showing how to parse the JSON feed content. ; nextUrl.i = CkUrl::ckCreate() If nextUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Get the URL for the next page in the feed. nextUrlStr.s = CkJsonObject::ckStringOf(json,"paging.next") While CkJsonObject::ckLastMethodSuccess(json) = 1 Debug "Next page URL: " + nextUrlStr CkUrl::ckParseUrl(nextUrl,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. CkRest::ckClearAllQueryParams(rest) CkRest::ckAddQueryParams(rest,CkUrl::ckQuery(nextUrl)) responseJson = CkRest::ckFullRequestNoBody(rest,"GET","/v2.7/me/feed") If CkRest::ckLastMethodSuccess(rest) <> 1 Debug CkRest::ckLastErrorText(rest) CkOAuth2::ckDispose(oauth2) CkRest::ckDispose(rest) CkJsonObject::ckDispose(json) CkUrl::ckDispose(nextUrl) ProcedureReturn EndIf CkJsonObject::ckLoad(json,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 = CkJsonObject::ckStringOf(json,"paging.next") Wend Debug "No more pages in the feed." CkOAuth2::ckDispose(oauth2) CkRest::ckDispose(rest) CkJsonObject::ckDispose(json) CkUrl::ckDispose(nextUrl) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.