尊敬的程序员同事们,
我正在做我的B&B的网站www.bordemundo.com,并希望在我的网站标题中包含我最新的facebook页面状态更新。
当谈到JQuery时,我不是一个破解者,我运行了谷歌并编辑了一个运行良好的脚本。我设法去掉了我实际上不需要的日期戳,因为状态每天只会改变一次。现在我注意到,当我分享另一个页面的朋友的相册或任何链接或数字信息时,它也会更新。
我宁愿只获取我自己键入的状态更新。你们中有人知道我如何通过使用我编辑的脚本轻松管理吗?我在下面附上了代码。
谢谢你的考虑,我真的很感激你的帮助!
(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)
是,从读取页面提要更改为读取页面状态。请参阅:http://developers.facebook.com/docs/reference/api/page/
您还可以通过检查每个项目的post.from.id并确保id是您想要显示的海报的id来确保项目的海报是您想要的样子