Use Facebook API to get a user's public feed (without up-to-date user access_token) - facebook

I've seen several questions regarding this topic in stackoverflow, but I could not find a bottom-line answer to this question.
I have a Facebook app.
I have a website to which users register using their FB account.
I would like to be able to get public posts from users' feeds using Facebook's API when the feeds update, even when the users are not logged into FB or into my website.
I was able to successfully subscribe to FB real-time updates.
I was able to see a user's public posts in http://www.facebook.com/<uid>/feed.
I tried to access https://graph.facebook.com/<uid>/feed - I got "An access token is required to request this resource.".
So I created an app access_token (using https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET).
I then tried to supply the app access_token I received when accessing the user's feed: https://graph.facebook.com/<uid>/feed?access_token=APP_ACCESS_TOKEN.
This time, I didn't get an OAUTH error, but just an empty JSON array: "{ "data": [ ] }"
The user in question gave the following permissions to my app: "email,read_stream,export_stream" (using the scope parameter in the FB.login API call).
At the moment it seems to me that the only way to get a user's feed via API is to wait for the user to log back into my website, get a user access_token, and only then make the calls.
I would appreciate it if anyway could confirm the above conclusion, or even better: let me know what I'm doing wrong...
Thanks!

Related

Facebook Graph API subscribed_apps edge only works with pages I own

Introduction
I have a Facebook APP and it is already published and approved to access the manage_pages and pages_messaging permissions. Facebook Login and Messenger are also installed. I also have a Webhook set and it works well.
My objective
I would like to make it easy for my users to create and publish a bot within the app, like what Chatfuel does. The user logins in using Facebook, create a new bot, link to a page and automatically the bot is available for use. The user will not be involved in manual configuration of the bot publishing process but rather simply pointing the page they would like the bot to appear.
What I have done so far
Login user with Facebook and collect their access_token and user_id using the app_token
Using the token, retrieve the pages owned by the user GRAPH_API_URL/me/accounts?access_token=USER_ACCESS_TOKEN
From the results obtained above, I'm able to display the pages to the users for them to choose where to publish the bot. I'm able to get the selected PAGE_ID and PAGE_ACCESS_TOKEN for use in the next step
I then send a POST request to subscribed the app to the page. Remember the app is the same one they used to login and approve the needed permissions as per my defined scope ('email', 'public_profile', 'manage_pages', 'publish_pages', 'pages_show_list')
Subscribing app to a page, I send a POST request to:
https://graph.facebook.com/v2.10/PAGE_ID/subscribed_apps?access_token=PAGE_ACCESS_TOKEN
The response I got was a success:
{"success": true}
The Problem Using the pages I own the process works well and I'm able to chat with the bots and from the app dashboard I can clearly see the pages have been added to the subscription list. My users are able to go through the all process, and from the logs, they also get a success response but their pages are not added and they cannot chat with the bot. To verify their subscriptions, I sent a GET request to https://graph.facebook.com/v2.10/PAGE_ID/subscribed_apps?access_token=PAGE_ACCESS_TOKEN and the response is positive as shown in the example below:
{
"data": [
{
"link": "http://mywebsite.com/",
"name": "MyApp",
"id": "1438393....."
}
]
}
From the highlighted steps, is there anything I might be missing? How can I get the above done properly? Thanks in advance for your input.

App token returns less posts than user access token

I need to request all posts on a public Facebook page. I do this with the following command:
https://graph.facebook.com/108062775923510/posts?access_token=[APP_ID]|[APP_SECRET]&limit=100
When I call this, I don't get all posts which are actually posted on that page. When I use instead a user access token, my request returns all latest posts. But using a user access token is not an option since this command is frequently executed by the server.
Does anyone know what a possible solution might be?

Getting Public Facebook Posts with an App Token

I'm using the facebook graph api to access publicly posted information of an arbitrary user. I'm using my own profile for testing and have posted a single public post.
The endpoint that I'm using is:
https:graph.facebook.com/v2.4/{id}/feed
However, this endpoint returns an empty set of data:
{
"data": [
]
}
This occurs regardless of which type of access token I use. I've tried an app access token, a regular access token with no additional permissions, and a regular access token with 'user_posts' selected. I'm especially confused about receiving no data with the last access token as that should include all posts that I've made.
I'd much prefer to use an app access token if possible - it's much easier to get a new one than it is to prompt a user to allow access. What am I doing wrong here?
This can't be done for all users. Facebook requires a person to be logged in order to see public posts from certain users. App credentials won't work to see an arbitrary user's public posts.

As a "normal Facebook user" I can access the friends of a friend of mine. But why do I need an "access token" to get the SAME INFO through graph api?

Don't think as developer yet. I'm a Facebook "normal user" and I'm logged. Then I access a friend 'X' profile. As a friend, I can see all the friends of friend X through this url:
https://www.facebook.com/friendx/friends
Fine... I can close the browser and, when I open it again, I can access the same url and see my friend's friends. And it's fine, because there is a cookie telling the server who I am.
But now, I'm still logged and I wanna retrieve all the friends of friend X throught graph api request, so i access this url:
https://graph.facebook.com/friendx/friends
And the error is, according to the documentation, expect:
An access token is required to request this resource.
I can't understand why facebook needs an access token. I'm logged in both cases. That cookie, in the second situation, is useless when I try to access the same information through graph api request.
What I wanna mean is: I don't wanna parse a whole html page to know who are friends of my friend. Parsing json is much easily.
The Facebook API requires authentication from the user to make that GET request, therefore you need an access_token saying that the user gave permission for you to access their friends list.
You cannot get an access_token from your cookies as it has to be generated via the API after the user approves your app.
If you want to test the graph API consider using the Graph API Explorer to generate an access token and generate the request but you should not use this as a solution to your answer.
consider reading the facebook documentation on access_tokens to further understand how the facebook API and authentication work.
The facebook GraphAPI doesnt allow us to collect the data which belongs to someone else. As you said you can access the friend's friend but at that time you are not collecting data for personal use, so that is allowed. That data is public so you can access, but I certainly doubt that they do allow us to access that data through GraphAPI or any other API. Also scrapping Facebook data is not against the facebook policies.

No access token facebook application authentication

I'd like to show my facebook wall posts on my website.
So i don't want to authenticate users with a dialog, to grant them some rights, i just want to show him my wall with comments (no ability to add comment just read only access).
As i know there isn't unexpired tokens now so is it possible to access just my data without requesting token every time it expires?
I'm using asp.net mvc but i think this sultion doesn't depend at platform at all.
You should:
Make your Facebook Posts public
Call the API endpoint: https://graph.facebook.com/{your_id}/feed?access_token={app_access_token} with your user_id and valid application access_token
Show the results on your website.
The App Access Token doesn't expire so you won't have a problem. As long as the posts are public, the API will be able to pick them up. In theory, your posts should be public anyway so anonymous users can see this.
This also gives you the ability to share stuff privately and not have it show up on your website.