Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Posts from a managed Page without login on Facebook #23

Open
biapar opened this issue Apr 6, 2019 · 0 comments
Open

Get Posts from a managed Page without login on Facebook #23

biapar opened this issue Apr 6, 2019 · 0 comments

Comments

@biapar
Copy link

biapar commented Apr 6, 2019

I manage a Facebook page and I with to get post on the site.
I'm able to get post putting in the page access token taken from Facebook Api Explorer, but this is not the good manner.
So by code, I'm able to get app token but not to get page token without pass fb auth page to get active auth token.
How to retrieve the posts by code?

My code:

FacebookOAuthClient client = new FacebookOAuthClient(appId, appSecret);

// Get an app token for the application (makes a call to the Facebook API)
  Skybrud.Social.Facebook.Responses.Authentication.FacebookTokenResponse accessToken = client.GetAppAccessToken();

var service = Skybrud.Social.Facebook.FacebookService.CreateFromAccessToken(accessToken.Body.AccessToken);

   

    Skybrud.Social.Facebook.Options.Posts.FacebookGetPostsOptions opt = new Skybrud.Social.Facebook.Options.Posts.FacebookGetPostsOptions()
    {
        Identifier = "xyz",
        Fields = "id,name_with_location_descriptor,feed",
        Limit = 20,

    };
    
     Skybrud.Social.Facebook.Options.Posts.FacebookGetPostsOptions opt2 = new Skybrud.Social.Facebook.Options.Posts.FacebookGetPostsOptions()
    {
        Identifier = "xyz",
        Fields = "fields=id,name_with_location_descriptor,feed{message,created_time,name,full_picture,picture,story,description,from,likes}",
        Limit = 20,

    };

    FacebookService facebookService = FacebookService.CreateFromAccessToken("access_token");


    // Make the request to the API
    FacebookGetPostsResponse responseFB = facebookService.Posts.GetPosts(opt2);
    
     FacebookFieldsCollection fields = new FacebookFieldsCollection(
        FacebookPostFields.Id,
        FacebookPostFields.Message,
        FacebookPostFields.Story,
        FacebookPostFields.CreatedTime,
        FacebookPostFields.From,
        FacebookPostFields.Picture,
        FacebookPostFields.Link

    );

     
foreach (var post in responseFB.Body.Data)
    {

        // Write some of the account information to the output stream
        <p>ID: @post.Id</p>
        <p>Name: @post.Name</p>
        <p>@post.Description</p>
        <p>@post.CreatedTime</p>
        <p>@post.Link</p>
        
          FacebookGetPostResponse response = facebookService.Posts.GetPost(post.Id, fields);

 
    FacebookPost postdata = response.Body;

    <p>ID: @postdata.Id</p>
    <p>Message: @postdata.Message</p>
    <p>Story: @postdata.Story</p>
    <p>Created: @postdata.CreatedTime</p>
        <p>foto: @postdata.Picture</p>
         <p>@postdata.Link</p>
          @postdata.Likes
        <hr />

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant