abjerner / Skybrud.Social

Skybrud.Social is a framework in .NET for integration with various social services like Twitter, Facebook and Instagram. The framework will handle all the technical parts and API communication so you don't have to.
http://social.skybrud.dk/
MIT License
96 stars 32 forks source link

Facebook - some pages unable to be found #41

Closed Krustocious closed 8 years ago

Krustocious commented 8 years ago

Hello again,

I've found another issue that isn't related to my earlier one, so I figured I would make a separate thread. My issue is that I am not able to find/display data from certain pages. I thought this might be some sort of permission problem, but I am able to find them using the graph API (both 2.2 and 2.4). It might be something they have in common that makes them unable to be found using the FacebookPostsResponse response = service.Posts.getPosts(pOptions), or it might be something entirely different.

I discovered this while looking for a page's likes, as not all of them were being included in the response.Body.Data of the likes response.

I have a few examples, see if you can return any data from them: Page Name: counterstrike Id: 72493026282 Page Name: thewitcher Id: 9659019330 Page Name: fallout Id: 20320777672

abjerner commented 8 years ago

Hi

What exactly happens when you try to fetch the posts from Facebook? I just tried fetching posts from the three pages, and it worked just fine - this is an example of my test code:

FacebookPostsResponse r = service.Posts.GetPosts(new FacebookGetPostsOptions {
    Identifier = "20320777672"
});

The result is the same whether I use the page ID or the alias. This is tested with both v2.2 and v2.4 and with Skybrud.Social 0.9.4.1.

abjerner commented 8 years ago

A little follow up question: you wouldn't by any change be using an app access token?

The three pages that you're mentioning seems to require visitors to be logged in (eg. try visiting the pages in incognito mode). Since an app access token doesn't have a user context, and you therefore can't fetch posts (or information in general) for these pages. If you use a user access token instead, it would work fine (in my last comment, I had only tested using a user access token).

Hope this makes sense ;)

Krustocious commented 8 years ago

Hi Anders,

I am currently using an app access token, and I think you're right - the pages won't let you view any data if you are not logged in. I have tried to swap over to a user access token, but I'm having some difficulty. I have a few questions about it:

What exactly should the state be? The documentation was a little unclear, it only says it is a string that "should be something that uniquely identifies the user on your site".

Is it possible to do this without the use of ASP.NET? I'm trying to do all this on just a localhost c# application without the use of a website. I seem to be unable to achieve the line string accessToken = client.GetAccessTokenFromAuthCode(Request.QueryString["code"]); as I'm not sure how to include Request without ASP.NET.

Is there another way to get the authorization code?

abjerner commented 8 years ago

Hi again,

Normally you should use an app access token for something like this, but since the pages requires users to login, you have to use a user access token instead, which comes with some challenges.

The state can just be a random value - I normally just generate a new GUID, and then use that as the state. The purpose is that you generate a state, save it in the user session or similar, and validate against that once the user is redirected back to your site. But as far as I remember, the state is optional, so you can skip it if you're just setting up a login page for yourself.

The steps for authentication that I have described for Skybrud.Social, uses what is called a server flow, and it requires ASP.NET (or some other form of website if not using Skybrud.Social). Facebook has some other ways of obtaining a user access token, but none that are supported in Skybrud.Social.

You can however also grab a user access token for your app at this page: https://developers.facebook.com/tools/accesstoken/

That access token will expire after about an hour, so you can instead go to https://developers.facebook.com/tools/debug/ and enter the access token. You will be given the option to "Extend Access Token", which will give you a new user access token with a lifetime of about two months. Once that token has expired, you will have to repeat the same steps again.

Krustocious commented 8 years ago

Hi Anders,

Thanks for the help, I'll try and get it working with the user access token, but maybe I can get by with what I can get from the app access token.