Facebook Graph API: find all public pages I like in a single request - facebook

I would like to know which objects returned from /me/likes are public ie. don't require authorization.
So far, I haven't found a better solution than making another request to /?ids=<IDs> without the access token, where <IDs> is a comma-separated list of IDs obtained from the previous request.
Is there any field indicating whether an object is public? Any help will be highly appreciated!

This is a matter of what you're asking for when you get the auth toke. If you have all boxes unchecked you will get just public information from the request. You'll know this by the pop-up asking for authorization saying
"Graph API Explorer will receive the following info: your public profile."
How ever if you have the box checked that says "user_likes" you'll get a list of all the likes. The authorization will say.
"Graph API Explorer will receive the following info: your public profile and likes."
If you just want to return the id of the things you like you can use this.
me?fields=likes{id}

Related

Searching public profiles using Facebook Graph API

I am looking to search Facebook public profiles using the Graph API with parameters like name, location and age. To accomplish this I created a Facebook app to get an app ID but I am unsure as to how to proceed to make the query to the API.
To try it out I tried using the explorer (https://developers.facebook.com/tools/explorer/) but I am unable to get any results that does not contain "me". I made sure to get a access token and enter a query like the following:
search?q=tobias&type=user&fields=id,name
The only reply is:
{
"data": [
]
}
I feel like I am missing something but I have been unable to figure out what, please advice.
The search endpoint is broken since 2018-04-04 for certain search types, including pages and users.
Search API
You can no longer use the /search endpoint with the following object types:
event
group
page
user
See
https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#search-4-4
Due to what has recently been in the news, searching for users has been deprecated, and is not supported through Facebook APIs.

Facebook graph api - Unsupported get request

I'm creating a custom module in Drupal, that for part of its functionality must fetch posts from a business page. So for simplicity, I'm using fbapp module as a dependency (drupal.org/project/fbapp), so that I can use it's authentication and request functions (fbapp_app_authenticate() and fbapp_graph_request()) without having to worry about the constant facebook graph updates making my own code obsolete.
I've created a facebook app, so authentication should be app token, using appid and app secret. This seems fine and I'm getting back access_token. However, when I try to read posts from a publicly available page (the clients), I get the response:
"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api"
Here's the queries and responses my code produces:
graph.facebook.com/oauth/access_token?client_id=<redacted>&client_secret=<redacted>&grant_type=client_credentials
array(1) {
["access_token"]=>
string(43) "<redacted>|<redacted>"
}
graph.facebook.com/<page_id>/posts?access_token=<redacted>|<redacted>"
string(183) "{"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}}"
Can anyone verify a correct way to query a Facebook page programmatically, perhaps there's a setting in the page I'm querying that I need to set (although I can't find anything)?
If page restrictions apply, the page's feed can only be retrieved with an user access token as far as I know (because FB needs to evaluate the visibility criteria, and setting your app to the same restrictions doesn't help here):
See
https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#readperms
It looks like everything you have done is correct. The response you got can be (i am not sure) because you got your clients pageid wrong.

Understanding Facebook Graph API identifiers

While I do realize that the ids for graph api objects are not documented, I'm seeing some oddities which I'd like to understand.
I have an authorized app that polls a page's feed for new comments and it looks like I'm getting different ids for the same post.
On first run I get a post with the id of:
1470990656482896_1553567768225184
Which is the id of the page and post joined by an underscore.
The second poll which ran a few minutes later, I received the same post with a different id:
100008124617959_1553567768225184
Which is the user id of the poster and post joined by an underscore.
While I'd like to understand the inconsistency, the real problem is trying to access the post via the second identifier returns an Unsupported get request with the code of 100
The post is public and is accessible via both
https://www.facebook.com/100008124617959/posts/1553567768225184
and
https://www.facebook.com/1470990656482896/posts/1553567768225184
This sounds like an oauth problem. While the post is public, to access it via the graph API you have to use an access token.
If you use the access token for Hans Gotwo then you should be able to access the post with the id of 100008124617959_1553567768225184
Looks like it's a bug. thanks #phwd
https://developers.facebook.com/bugs/721538487964698/

Facebook Graph API: Find graph object from post URL

Given the URL of a public Facebook post, how can one find the post object in the FB Graph API? (secondarily, why are so many user feeds empty or nearly empty when accessed through the API?)
We would like to be able to comment on or like a post via the v2.x
Graph API, given the post's URL. Doing so requires the post's object
ID, which we can make some educated guesses about, but accessing
the actual object through the API has proven unreliable (works for some posts but
not others).
v2 of the API introduced app-scoped user IDs, and post IDs generally seem
to be of the form {app-scoped user id}_{unique post id}. Here are the
details of some attempts to find posts in the API with various combinations of
these IDs (global user id, app-scoped user id, and post id).
Starting with a simple example: https://www.facebook.com/evan.prodromou/posts/10153023417510505. Key characteristics are that it's public, it's not a share of another post, and most importantly it has no photo(s), which add extra ids and URLs for the individual photo(s) and photo set. Evan's profile is also public, i.e. https://www.facebook.com/evan.prodromou doesn't show the generic This content is currently unavailable
Trying the bare post id from that URL, /v1.0/10153023417510505 and /v2.2/10153023417510505 both give the Unsupported get request (code 100) error.
Evan's global user id is 525575504. Attaching that as a prefix, /v1.0/525575504_10153023417510505 and /v2.2/525575504_10153023417510505 still both give the same Unsupported get request error.
Same error using his app-scoped user id instead, /v2.2/10152350676805505_10153023417510505.
OK let's try the other direction. We'll page through the user's feed until we find the post in question. It feels like this is more the expected use case for the API...
Both the global /v2.2/525575504/posts and app-scoped /v2.2/10152350676805505/posts return nothing, but /v1.0/525575504/posts returns two recent posts, this like and this post. Not sure why only those two, even though has plenty of other recent public posts. The like is fetchable via its id field in both api versions, i.e. /v1.0/525575504_10153045879215505 and /v2.2/10152350676805505_10153045879215505, but both API versions return the Unsupported get request error when fetching the post via its id field, e.g. /v1.0/525575504_351575675029953 and /v2.2/10152350676805505_351575675029953
Trying another public post, this one with pictures: https://www.facebook.com/andigalpern/posts/678121182314631 . /v1.0/100003502653187_678121182314631, /v2.2/100003502653187_678121182314631, and /v2.2/499657186827699_678121182314631 all error.
/v1.0/100003502653187/posts only includes one post, a like, and /v2.2/100003502653187/posts is empty.
For reference, here is the GitHub issue where we have been tracking this problem.
Basically you would need read_stream for this (which your app will not get granted). And yes, even though the post is public, you still need read_stream to be able to get read access to all kinds of posts.
You can easily play around with this in Graph API Explorer. First give your app read_stream permission to get ids of items in your feed – that will give you ids of the “form app-scoped user id underscore post id”. Then remove read_stream (by clicking “Get Access Token” again and using the “Clear” button), and try several of the user_* permissions – and you will see that for most of your posts, even the public ones, you will still only get “Unsupported get request”, which just means you are not allowed to read that object.
F.e., I have a public post where shared a video post from another page on my timeline, the type is video and status_type is shared_story, but neither user_status nor user_videos allow me to read this post – only when I grant read_stream again, my app can read that post. Same with another public post of type status and status_type mobile_status_update – readable with read_stream, not with any of the user_* permissions.
In short: What you want to achieve is not possible any more with API v2 and the restriction that read_stream will only be granted to apps on platforms where no official FB client exists.
A one proposition is to make api calls to write facebook posts since those return valid post_id that you could use
Second,
When you try https://developers.facebook.com/tools/explorer/256884317673197/?method=GET&path=525575504%2Fposts&version=v2.0&
You can see that his posts ID's are not starting with his public id as you wrote 525575504_*
but they still put unsupported get request
https://developers.facebook.com/tools/explorer/256884317673197/?method=GET&path=10152853212485505_351575675029953&version=v2.0
Third since above doesnt work are those posts public for sure?

Facebook Graph API and Generic Access token

If I understand correctly, the Graph API enables access to public pages using a generic access token. I'm finding however that many public pages are not returned in search results when using this type of token vs. a user token. I don't want users to have to go through an OAUTH dialog just to retrieve the basic properties of a public page.
This example below returns a result when using any user access token but no results when using a generic access token:
What am I doing, or understanding, incorrectly?
https://graph.facebook.com/search?q=OSullivansHerndon&type=page&access_token={myuseraccesstoken}
https://graph.facebook.com/search?q=OSullivansHerndon&type=page&access_token={APPID|APP SECRET}
You can get a generic access token for your app that will let you look at requests where you would otherwise need an access_token= parameter in the Graph call. You don't need to authenticate users as the access token is for the application.
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&
client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
example:
https://graph.facebook.com/nike/posts?access_token={response from above call}
I suspect you need a user access token to use /search as search results use social context. If you have the page id, you can load that without any access token by just hitting /id
I dont think you can get this to work without a user access token. From my limited OAUTH is the only way forward.
By specifying GRAPH API user token, you simply meant that you are using user preferences and information .
if your intention is to fetch some public page information , then you need that page userid or username . And , if you are intention is to grab all the public data which is available for your particular user , then you have to pass oAUTH system,Since indirectly you are accessing his information which is meant public under some facebook govern rules .
Accessing public page by providing user id
https://graph.facebook.com/19292868552
By writing the id of that page,you ca access its information. Now the question is how to access the id of that particular page, Manually just visit that page --> photo album . on the top of that page,you will see something like "Album Videos" . Just visit any of that link.now see,woola the id of that page is visible to you . something like this url
http://www.facebook.com/media/albums/?id=176101909092314
And btw,if you are interested in performing search , then you need to specify user token. facebook do some algorithmic search for all users and track user activities . So , the result will not always the same for you and me , as an example .