As far as I am aware, there is no ready package for Umbraco 7 for facebook feeds but creating your own is very simple and straightforward. I suggest to have your own piece of code.
The code above would return JSON from Facebooks graph API.
Please notice, that you have to create a facebook app before you start - https://developers.facebook.com/
Skybrud.Social, as Bjarne mentions, can help you with the authentication part (logging in), but has also mapped most of the Facebook Graph API.
Getting access to the API
To retrieve data from the Facebook API you need either an app access token or a user access token.
An app access token can be used to retrieve public data - like posts of the umbraco page. An app access token doesn't expire - and if you already have created an app on the Facebook developer site, you can find your app access token here: https://developers.facebook.com/tools/accesstoken/
If you need to retrieve private information - eg. posts of a page or user that is only visible when logged into Facebook, you need to obtain a user access token. You can read more about obtaining a user access token here: http://social.skybrud.dk/facebook/authentication/user-access-token/
A user access token expires after 60 days, and you'll have to obtain a new user access token.
Now some examples
Assuming that you already have obtained an access token at this point, your code could look like:
FacebookService facebook = FacebookService.CreateFromAccessToken("Enter your user access token or app access token");
foreach (FacebookPost post in facebook.Posts.GetPosts("umbraco").Body.Data) {
<p>
@post.CreatedTime.ToString("r"): @post.Message
</p>
}
However you should be aware that in most recent versions of the Facebook API, only a few fields will be returned by default, so you may experience that not all properties in the post object has a value.
If you need more fields / properties than just the message and creation date, you can explicitly tell the Facebook API to return more fields:
FacebookGetPostsOptions options = new FacebookGetPostsOptions("umbraco") {
Fields = "id,message,created_time,type"
};
foreach (FacebookPost post in facebook.Posts.GetPosts(options).Body.Data) {
<p>@post.Id (@post.Type)</p>
}
Facebook feed
Is there a simple way to display a Facebook feed on a website? I can't see any (active) projects on here and Goole isn't being helpful at the moment.
I guess I could write my own, but was hoping there was something ready built !
As far as I am aware, there is no ready package for Umbraco 7 for facebook feeds but creating your own is very simple and straightforward. I suggest to have your own piece of code.
OK, suspected as much - do you happen to have any example code yourself or have a link to a basic example, to get me started?
I haven't used this package in a project yet, but have you tried with Skybryd.Social?
I am not sure how much of the API that is implemented and the code isn't fully documented.
But it might be worth taking a look at it: http://social.skybrud.dk/facebook/endpoints/
/Bjarne
I think I may have seen that before but assumed it was just for implementing logging on using ...
However it does look like it does much more than that, so I'll investigate further.
Hi Gordon
Do you need a feed for a page or a user?
Urm, what's the difference (hoping that's not a stupid question!)?
You would need to auth before you can access a users wall and so on.
If you just need to get posts from a Facebook Page, you could do this:
The code above would return JSON from Facebooks graph API. Please notice, that you have to create a facebook app before you start - https://developers.facebook.com/
I don't believe the above code will work. Instead you need to be using the new Graph API as the feeds/page.php end point has been discontinued.
https://developers.facebook.com/docs/apps/changelog#v2390daydeprecations
Skybrud.Social, as Bjarne mentions, can help you with the authentication part (logging in), but has also mapped most of the Facebook Graph API.
Getting access to the API
To retrieve data from the Facebook API you need either an app access token or a user access token.
An app access token can be used to retrieve public data - like posts of the umbraco page. An app access token doesn't expire - and if you already have created an app on the Facebook developer site, you can find your app access token here: https://developers.facebook.com/tools/accesstoken/
If you need to retrieve private information - eg. posts of a page or user that is only visible when logged into Facebook, you need to obtain a user access token. You can read more about obtaining a user access token here: http://social.skybrud.dk/facebook/authentication/user-access-token/
A user access token expires after 60 days, and you'll have to obtain a new user access token.
Now some examples
Assuming that you already have obtained an access token at this point, your code could look like:
However you should be aware that in most recent versions of the Facebook API, only a few fields will be returned by default, so you may experience that not all properties in the
post
object has a value.If you need more fields / properties than just the message and creation date, you can explicitly tell the Facebook API to return more fields:
You can see a list of available fields in the Facebook documentation: https://developers.facebook.com/docs/graph-api/reference/v2.5/post#fields (some fields are not mapped in Skybrud.Social yet).
I hope this helps you in the right direction ;)
Im trying to get the creationdate when using the options but I get no hit. @post.Creationdate is not working and @post.CreatedTime is empty?
I can see that my example was wrong, as
creation_date
really should becreated_time
- I have updated the example to fix this ;)If you change this in your code as well,
@post.CreatedTime
should expose the correct time.is working on a reply...