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
(Unicode C) Facebook User Feed (Read Posts)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.
#include <C_CkOAuth2W.h> #include <C_CkRestW.h> #include <C_CkJsonObjectW.h> #include <C_CkDateTimeW.h> #include <C_CkDtObjW.h> void ChilkatSample(void) { HCkOAuth2W oauth2; HCkRestW rest; BOOL success; const wchar_t *responseJson; HCkJsonObjectW json; HCkDateTimeW dtime; BOOL bLocalTime; HCkDtObjW dt; int i; int numItems; const wchar_t *message; const wchar_t *story; const wchar_t *prevUrl; const wchar_t *nextUrl; // 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 = CkOAuth2W_Create(); CkOAuth2W_putAccessToken(oauth2,L"FACEBOOK-ACCESS-TOKEN"); rest = CkRestW_Create(); // Connect to Facebook and send the following GET request: success = CkRestW_Connect(rest,L"graph.facebook.com",443,TRUE,TRUE); if (success != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkOAuth2W_Dispose(oauth2); CkRestW_Dispose(rest); return; } // Provide the authentication credentials (i.e. the access key) CkRestW_SetAuthOAuth2(rest,oauth2); // We could limit the number of posts. The default limit is 25. CkRestW_AddQueryParam(rest,L"limit",L"5"); responseJson = CkRestW_fullRequestNoBody(rest,L"GET",L"/v2.7/me/feed"); if (CkRestW_getLastMethodSuccess(rest) != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkOAuth2W_Dispose(oauth2); CkRestW_Dispose(rest); return; } json = CkJsonObjectW_Create(); CkJsonObjectW_putEmitCompact(json,FALSE); CkJsonObjectW_Load(json,responseJson); // Show the JSON in human-readable format. wprintf(L"%s\n",CkJsonObjectW_emit(json)); // A sample JSON response is shown below. // This is the code to parse the JSON response. dtime = CkDateTimeW_Create(); bLocalTime = TRUE; i = 0; numItems = CkJsonObjectW_SizeOfArray(json,L"data"); while (i < numItems) { CkJsonObjectW_putI(json,i); wprintf(L"--- %d\n",i); message = CkJsonObjectW_stringOf(json,L"data[i].message"); if (CkJsonObjectW_getLastMethodSuccess(json) == TRUE) { wprintf(L"message: %s\n",message); } story = CkJsonObjectW_stringOf(json,L"data[i].story"); if (CkJsonObjectW_getLastMethodSuccess(json) == TRUE) { wprintf(L"story: %s\n",story); } wprintf(L"id: %s\n",CkJsonObjectW_stringOf(json,L"data[i].id")); // We can load the created_time into a CkDateTime... CkDateTimeW_SetFromTimestamp(dtime,CkJsonObjectW_stringOf(json,L"data[i].created_time")); dt = CkDateTimeW_GetDtObj(dtime,bLocalTime); wprintf(L"%d/%d/%d %d:%d\n",CkDtObjW_getMonth(dt),CkDtObjW_getDay(dt),CkDtObjW_getYear(dt),CkDtObjW_getHour(dt),CkDtObjW_getMinute(dt)); CkDtObjW_Dispose(dt); i = i + 1; } // Finally, there are two paging URLs at the very bottom. Those can be accessed as shown: prevUrl = CkJsonObjectW_stringOf(json,L"paging.previous"); wprintf(L"URL for previous page: %s\n",prevUrl); nextUrl = CkJsonObjectW_stringOf(json,L"paging.next"); wprintf(L"URL for next page: %s\n",nextUrl); // ------------------------------------------------------------------- // 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" // } // } // CkOAuth2W_Dispose(oauth2); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(json); CkDateTimeW_Dispose(dtime); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.