React Native
React Native
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 React Native Downloads
import { JsonObject, OAuth2, Rest, Url } from '@chilkat/react-native'
async function 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
const oauth2 = new OAuth2();
oauth2.accessToken = 'FACEBOOK-ACCESS-TOKEN';
const rest = new Rest();
// Connect to Facebook and send the following GET request:
try {
await rest.connectAsync('graph.facebook.com', 443, true, true);
} catch {
console.log(rest.lastErrorText);
return;
}
// Provide the authentication credentials (i.e. the access key)
rest.setAuthOAuth2(oauth2);
// Gets the 1st page in the user's feed.
let responseJson: string;
try {
responseJson = await rest.fullRequestNoBodyAsync('GET', '/v2.7/me/feed');
} catch {
console.log(rest.lastErrorText);
return;
}
const json = new JsonObject();
json.emitCompact = false;
json.load(responseJson);
// See Parsing the Facebook User Feed for code showing how to parse the JSON feed content.
//
const nextUrl = new Url();
// Get the URL for the next page in the feed.
let nextUrlStr = json.stringOf('paging.next');
while (json.lastMethodSuccess) {
console.log(`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 = await rest.fullRequestNoBodyAsync('GET', '/v2.7/me/feed');
} catch {
console.log(rest.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');
}
console.log('No more pages in the feed.');
}