Dart
Dart
Iterate Pages in Feed
See more Facebook Examples
Demonstrates how to read the next page in the user's Facebook feed, and iterates through all of the pages in the Facebook feed.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// 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
final oauth2 = CkOAuth2();
oauth2.accessToken = 'FACEBOOK-ACCESS-TOKEN';
final rest = CkRest();
// Connect to Facebook and send the following GET request:
try {
rest.connect('graph.facebook.com', 443, true, true);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Provide the authentication credentials (i.e. the access key)
rest.setAuthOAuth2(oauth2);
// Gets the 1st page in the user's feed.
String responseJson;
try {
responseJson = rest.fullRequestNoBody('GET', '/v2.7/me/feed');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final json = CkJsonObject();
json.emitCompact = false;
json.load(responseJson);
// See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
//
final nextUrl = CkUrl();
// Get the URL for the next page in the feed.
var nextUrlStr = json.stringOf('paging.next');
while (json.lastMethodSuccess) {
print('Next page URL: $nextUrlStr');
nextUrl.parseUrl(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.
rest.clearAllQueryParams();
rest.addQueryParams(nextUrl.query);
try {
responseJson = rest.fullRequestNoBody('GET', '/v2.7/me/feed');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
json.load(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 = json.stringOf('paging.next');
}
print('No more pages in the feed.');
}