Dear fellow programmers,
I am working on my B&B’s website http://www.bordemundo.com and would like to include my very latest facebook pages status update in the header of my website.
As I am not a crack when it comes to JQuery I ran Google and edited a script which works just fine. I managed to get rid of the date-stamp that I actually do not need, as the status would change exactly once a day. Now I noticed that it does also update when I share another page’s friend’s phot album or any link or digital information.
I would rather only fetch the status updates that I type in myself. Has anyone of you an idea how I could easily manage this by using the script that I edited? I attached the code below.
Thx for considering and I really appreciate any help!
(function($) {
$.fn.faceFeed = function(options) {
/**
* Configuration
*
* `pageName:` The name of your Facebook page. Required.
* `tokenGenerator:` Path to a file that will return a JSON access_token. If defined, this will take
* priority over `accessToken`.
* `accessToken:` A token you generate at <https://developers.facebook.com/tools/explorer>.
* `dateClass:` The class of the `<span>` that contains your date "ago in words". Default: `post-date`
*/
var config = {
pageName: '',
tokenGenerator: '', // default: token.php
accessToken: '',
postsToFetch: 1
};
$.fn.extend(config, options);
/**
* Converts "http://" links into <a> tags.
*
* @param {String} a block of text for which all "http://" links need conversion
* @return {String} the same block of text with URLs re-formatted.
*/
function linkify(text){
if (text) {
text = text.replace(
/((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url){
var full_url = url;
if (!full_url.match('^https?:\/\/')) {
full_url = 'http://' + full_url;
}
return '<a href="' + full_url + '">' + url + '</a>';
}
);
}
return text;
}
/**
* Requests your page's status feed from the Open Graph and injects it as HTML into the
* element.
*
* @param {String} accessToken - A generated or provided access token for authorizing
* with the API.
*/
function getPosts(accessToken, self) {
$.ajax({
url: 'https://graph.facebook.com/'+config.pageName+'/feed',
type: 'GET',
data: {
access_token: accessToken,
limit: config.postsToFetch
},
dataType: 'json',
success: function(response) {
self.html('');
for (var c=0; c < response.data.length; c++) {
var status = response.data[c];
var statusMessage = (status.message) ? status.message : status.story;
var txt = linkify(statusMessage);
var row = $('<span class="status"></span>').html(txt);
self.append(row);
}
}
});
}
/*
* Runtime.
*/
return this.each(function() {
var self = $(this);
self.html('<p>Lade Neuigkeiten...</p>');
if (config.tokenGenerator) {
$.ajax({
url: config.tokenGenerator,
type: 'GET',
dataType: 'json',
success: function(generator) {
getPosts(generator.access_token, self);
}
})
} else {
getPosts(config.accessToken, self);
}
});
};
})(jQuery)
Yes, change from reading the page feed to reading page statuses. See: http://developers.facebook.com/docs/reference/api/page/
You can also be sure the poster of the item is who you want it to be by checking each item’s post.from.id and ensuring that ID is the ID of the poster you want to display