How to Get feed of public Facebook page using Graph api? - facebook

There are already several questions on StackOverflow ( Can you get a public Facebook page's feed using Graph API without asking a user to allow? Get public page statuses using Facebook Graph API without Access Token? )concerning my question: I need to get through the graph API the feeds of a public page on facebook.
I followed the instructions but I always get:
{"Error": {"message": "An access token is required to request this resource.", "Type": "OAuthException", "code": 104}}
how can I fix this? I'm going crazy because everyone seems to work except me! thanks

Based on your description, the error is that you weren't supplying a valid access token with your request.
If the app's type is set to 'Native / Desktop' it's assumed you distributed the app's secret key with the binary, and thus the app access token isn't trusted (and 'getAccessToken' in the PHP SDK will only work when real users log in, it can't fall back to the app token)
If you were attempting to use the app access token to read the page's feed, this would fail in the manner you described.

Related

Facebook app token not working, but access token works

I have a really weird situation here, and I've looked everywhere through Facebook's documentation with no answers.
I'm trying to get get recent posts from multiple Facebook pages. But one of them keeps crashing. It won't work when I'm using an app token. It works if I'm using access tokens, but those expire, so it'd be better to not use that.
https://graph.facebook.com/norgeshushonefoss/posts?access_token=myAppToken
gives this result:
{
"error": {
"message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100
}
}
While this url gives me the recent posts: https://graph.facebook.com/norgeshus/posts?access_token=myAppToken
I can't see any difference in those two. Are there any page settings that may cause an app token not to authorize for some reason?
If the page has any access restrictions in place (age, location, alcohol-related content), then you can not access any of its info using your app access token.
It needs a user access token for a user that qualifies to see the page (or a page access token).

Facebook Graph API "/{page-id}/feed" is not working with App Access Token

We are facing issues with Graph API. The Facebook Graph API "/{page-id}/feed" is not working for all pages with a valid App Access Token. Previously it used to work. We noticed it today the API is throwing error
{
"error": {
"message": "An unknown error has occurred.",
"type": "OAuthException",
"code": 1
}
}
Not working pages:
https://graph.facebook.com/22934684677/feed?access_token=
https://graph.facebook.com/42798291365/feed?access_token=
Note: And its working if we pass a User Access token instead of App Token.
Facebook developer Docs says "An access token is required to view publicly shared posts." So App Access Token should work!
Does Facebook change something inside the API?. Can any one help to solve the issue
You should use a Page Token for Page data. Pages not working with an App Token are most likely restricted by age or location. Since the App Token does not include any user session, you canĀ“t be sure if the user should have access to it.
If it does not work with an App Token AND the Page is definitely not restricted, file a bug.
This is happening because some of the posts returned might have extra restrictions on them which need a user token to verify this. Use a page token or a user token as a workaround for this. Having said that, the request shouldn't fail with an unknown error and we're working on a fix for the same on the bug report here:
https://developers.facebook.com/bugs/783169051760311/

Can't get public info using Facebook Graph

I'm trying to get public profile using user_token. I registered FB app and get user_token from page: https://developers.facebook.com/tools/access_token/
but when I try to get public profile https://graph.facebook.com/100000378611443?limit=1000&access_token={user_token}
I see an error:
{
"error": {
"message": "The global ID 100000378611443 is not allowed. Please use the application specific ID instead.",
"type": "OAuthException",
"code": 2500
}
}
But if I use user_token in above URL from another my app I can successfully get public user profile.
What am I doing wrong?
Thanks.
Since v2.0 of Facebook API apps are no longer allowed to use global IDs, just app-scoped ID. These ID are generated when a user logs in onto your application.
If you are attempting to retrieve current logged in user's information, you should use /me endpoint along with the user's access token: https://graph.facebook.com/me?access_token={user_token}
Note that with these new scoped IDs, apps are not allowed to retrieve any data from users who haven't gave permissions to the app.
Cheers
You can still use the older version of Facebook Graph API V1.0 which will continue to exist until April 30th, 2015.
https://graph.facebook.com/v1.0/100000378611443
You must use access token, not user token! You can obtain one from Graph API Explorer here https://developers.facebook.com/tools/explorer
Then you must have at least user_about_me permission to get profile data. As many user data permissions you have, as many endpoints and data you obtain. Keep in mind, access token you get from Graph API Explorer is short living - expires in an hour or so. More about tokens and their terms here: https://developers.facebook.com/docs/facebook-login/access-tokens
Happens to me too, trying to using "Graph Api Explorer" with an user id obtained debugging my application.
User id that obtain from a call as:
../<event_id>/likes
isn't REAL user id, but a kind of id "encrypted" (let me use the word) with access_token.
So if you wanna test that user id on GAE, you need to specify also access token:
https://graph.facebook.com/<user_id>?access_token=<application_access_token>

How to get a Facebook access token for a page with no app or app secret

I am trying to automatically display wall posts from a Facebook page another website. I can use the Graph API explorer to get one manually. When I use the generated token in my code all is well. The problem is the tokens expire quickly. It just isn't practical to get a new code several times a day. I know there is a way to request an access token programatically - in my case via PHP, but all the examples call for an app secret. Since this is a page and not an app, there is no secret.
I have tried this:
https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=MY_CLIENT_ID&redirect_uri=http%3A%2F%2FMY_SITE_URL&scope=user_status
What I get back is this:
{
"error": {
"message": "Error validating application. Cannot get application info due to a system error.",
"type": "OAuthException",
"code": 101
}
}
I have tried using Fiddler to intercept the call from the Graph API explorer to see what I need in my code file, but haven't had any luck.
Use the app-id to build this link to authorize the managing of pages
https://www.facebook.com/dialog/oauth?client_id=MY_CLIENT_ID&redirect_uri=MY_SITE_URL&scope=manage_pages&response_type=token
Exchange token for perm (longer token)
https://graph.facebook.com/oauth/access_token?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&grant_type=fb_exchange_token&fb_exchange_token=(from link1)
Visit this page, find the PAGE you want to post and copy the new access_token
https://graph.facebook.com/me/accounts?access_token= (from link2)
Use this last token (form link3) to post to page as app
Take note as it will expire in 60 days. (FB no longer offering unlimited offline access token)
Edit (2013 Oct 24): 5th point no longer true, Page Access Tokens generated from long-lived User Tokens do not expire.
Edit (Feb 2016): Tokens now "usually" expire in 60 days but can be invalidated at any time.
For graph objects that are not private (public) you can use your app_id as an access_token.
Your app_id never changes so you don't ever have to renew it. The question is is the wall content yours?
If so you can easily use your app_id to accomplish this without having to request an access token everytime.
However, in order to have an app_id you need to create an application on facebook with a facebook developer account. As far as I understand there isnt a way to anonymously make request to the Graph API,

How to get the access_token for Facebook with no application

On the documentation page for Facebook Graph API there are a lot of example links such as https://graph.facebook.com/me/likes?access_token=SOME_AT
Could anyone explain how the access_token for these links are generated?
All I've read in the documentation were about getting access_token only for applications, but on that page everyone could get an access_token without one.
You can use the graph API to get public information. People set privacy settings on facebook, so to prevent social freaks from stalking you, they(fb) created Autorisation.What I believe is that on the documentation, they are generating the access token using the Developers App. You can generate this Access token by making an application and asking a user to Authorise your application to access his data using OAUTH dialogs. Usually people reading at developer.facebook.com have enabled the Developers app so it easily opens your information.
The Graph API as such allows you to
easily access all public information
about an object. For example,
https://graph.facebook.com/btaylor
(Bret Taylor) returns all the public
information about Bret. For example a
user's first name, last name and
profile picture are publicly
available.
To get additional information about a
user, you must first get their
permission. At a high level, you need
to get an access token for the
Facebook user. After you obtain the
access token for the user, you can
perform authorized requests on behalf
of that user by including the access
token in your Graph API requests:
The access_token in these links are generated using your Facebook identity and an application ID (presumable associated to "developers.facebook.com"). If you go to the same page with another Facebook account, you will see different access tokens.