Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1461 posts 1883 karma points
    Oct 27, 2015 @ 11:29
    Gordon Saxby
    0

    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 !

  • Amir 75 posts 224 karma points
    Oct 27, 2015 @ 11:59
    Amir
    0

    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.

  • Gordon Saxby 1461 posts 1883 karma points
    Oct 27, 2015 @ 12:12
    Gordon Saxby
    0

    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?

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Oct 27, 2015 @ 12:55
    Bjarne Fyrstenborg
    0

    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

  • Gordon Saxby 1461 posts 1883 karma points
    Oct 27, 2015 @ 13:16
    Gordon Saxby
    0

    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.

  • Søren Mastrup 122 posts 564 karma points c-trib
    Oct 27, 2015 @ 12:13
    Søren Mastrup
    0

    Hi Gordon

    Do you need a feed for a page or a user?

  • Gordon Saxby 1461 posts 1883 karma points
    Oct 27, 2015 @ 13:00
    Gordon Saxby
    0

    Urm, what's the difference (hoping that's not a stupid question!)?

  • Søren Mastrup 122 posts 564 karma points c-trib
    Oct 27, 2015 @ 13:17
    Søren Mastrup
    0

    You would need to auth before you can access a users wall and so on.

  • Søren Mastrup 122 posts 564 karma points c-trib
    Oct 27, 2015 @ 13:22
    Søren Mastrup
    0

    If you just need to get posts from a Facebook Page, you could do this:

    string appId = "xxxxxxxxxxxxx";
    string appSecret = "xxxxxxxxxxxxx";
    string pageId = "123456789";
    string url = "https://graph.facebook.com/v2.5/"+pageId+"/?fields=cover,name,likes,link,posts.limit(50){created_time,message,link,type,full_picture,picture,source,icon}&access_token="+appId+"|"+appSecret;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.ContentType = "application/json";
    var stream = new StreamReader(request.GetResponse().GetResponseStream());
    string response = stream.ReadToEnd();
    var feed = Json.Decode(response);
    

    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/

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    Oct 27, 2015 @ 13:04
    Nik
    0

    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

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    Oct 27, 2015 @ 13:54
    Anders Bjerner
    1

    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>
    
    }
    

    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 ;)

  • Fredrik Esseen 610 posts 906 karma points
    May 09, 2017 @ 15:00
    Fredrik Esseen
    0

    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?

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    May 09, 2017 @ 17:13
    Anders Bjerner
    0

    I can see that my example was wrong, as creation_date really should be created_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.

Please Sign in or register to post replies

Write your reply to:

Draft