how to get facebook post after a graph search? - facebook

https://graph.facebook.com/search?access_token=xxxxxx&q=hello&type=post&fields=from,message,picture,link,name,caption,description,created_time&limit=1&locale=en_US&scope=publish_stream,offline_access,user_status,read_stream
After such a graph search, I get some data like:
{
"data": [
{
"from": {
"name": "Eric Fluegge",
"id": "100000626293694"
},
"message": "Well, here's go nothing. Hello Tennessee.",
"created_time": "2013-03-30T19:23:44+0000",
"id": "100000626293694_567340783296793"
}
],
"paging": {
"previous": "https://graph.facebook.com/search?fields=from,message,picture,link,name,caption,description,created_time&q=hello&limit=1&type=post&locale=en_US&access_token=XXXXXXXXXXXXX&since=1364671424&__previous=1",
"next": "https://graph.facebook.com/search?fields=from,message,picture,link,name,caption,description,created_time&q=hello&limit=1&type=post&locale=en_US&access_token=XXXXXXXXXXXXX&until=1364671423"
}
}
so, is "id": "100000626293694_567340783296793" a post id? If so, how to use this post id, query again, get only this certain post information? I would like to store post id to mysql table, then I want to query the post anytime in the future, thanks.
EIDT: in app setting, i have set the publish_stream,offline_access,user_status,read_stream
EIDT2:
I have tried into Graph API Explorer, choose read_stream and generate a long live token.
SELECT post_id, actor_id, message, type, attachment FROM stream WHERE post_id = "100000626293694_567340783296793"
the result still empty. so I cannot get a post bcause i am not a friend of the post auther? or 100000626293694_567340783296793 is not a post id? or other reason?

Yep, the "id": "100000626293694_567340783296793" is a post ID, you can query its data again with the following URL: http://graph.facebook.com/100000626293694_567340783296793
Attention!
You should ask for the read_stream permission/scope too! Or else you'll get the following error:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
And of course, append the access_token to your GET url. (and don't forget https too)
You can check the Graph API Reference here: Post - Facebook Developer Reference

Related

FB Graph API Response Paging Next contains access_token

Now I am working with Graph API 3.2.
Is there any opportunities to configure within my request went to Graph API to not get back the access token in the end of the response param, called Paging Next?
i.e: here is the documentation.
I just don't want to get back the access token as a plain text in the repsonse, like here:
"feed": {
"data": [
{
"created_time": "2017-12-12T01:24:21+0000",
"message": "This picture of my grandson with Santa",
"id": "{your-user-id}_1809387339093972" // Post ID
},
{
"created_time": "2017-12-11T23:40:17+0000",
"message": ":)",
"id": "{your-user-id}_1809316002434439" // Post ID
},
{
"created_time": "2017-12-11T23:31:38+0000",
"message": "Thought you might enjoy this.",
"id": "{your-user-id}_1809310929101613" // Post ID
}
],
"paging": {
"previous": "https://graph.facebook.com/v3.2/{your-user-id}/feed?format=json&limit=3&since=1542820440&access_token={your-user-access-token}&__paging_token=enc_AdCgj6RSGWTYV7EXj2cFlOWJjbZCq8oI3ogIpLrxPCVK3U8Kad0EgsZA2vri3YKIwl71XGRDJz9C8TgqMeyiu8U5CD&__previous=1",
"next": "https://graph.facebook.com/v3.2/{your-user-id}/feed?format=json&limit=3&access_token={your-user-access-token}&until=1542583212&__paging_token=enc_AdDLmzUgWiLo6oHGCI53S5begiKOfNZBY0affrLMWgheBzfwMA7XSKmgjyNbuZBIptdXc18j1Se0Dm7vEsePh1SoM3"
}
},
"id": "{your-user-id}"
}
Thanks anyway!! :)
It is answered elsewhere: https://stackoverflow.com/a/29900228 but it is good to have a reference to that answer here, too.
The solution that worked for me with various Graph API versions is to pass the token in the Authorization header:
return requests.get(url,
headers={'Authorization': 'Bearer ' + token})
If the token travels in the header, it won't appear in the response anywhere.

Get facebook fans count using API 2.8

How to get Facebook fans count using http request in API 2.8
-- I test these requests but not working
This return an array but no Fans Count
https://graph.facebook.com/v2.8/{APP_ID}?access_token={ACCESS_TOKEN}&edges=fan_count
Return
{
"category": "Entertainment",
"link": {APP LINK},
"name": {NAME},
"id": {ID}
}
-- This throw an error array
https://graph.facebook.com/v2.8/{APP_ID}?access_token={ACCESS_TOKEN}&fields=likes
Return
{
"error": {
"message": "(#100) Tried accessing nonexisting field (likes) on node type (Application)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "FlkGoTOJ403"
}
}
This is the correct one:
https://graph.facebook.com/v2.8/{PAGE_ID}?access_token={ACCESS_TOKEN}&fields=fan_count
Not sure why you would use an App for this, Fans are for Pages.
Use {PAGE_NAME} instead of {APP_ID}
GET ACCESS TOKEN: https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET_KEY}&grant_type=client_credentials
GET FANS COUNT: https://graph.facebook.com/v2.8/{PAGE_NAME}?access_token={ACCESS_TOKEN}&fields=fan_count
Thanks for luschn

How to get the user data of a facebook group post? The original poster

I have gotten a post object from the Facebook Graph API as such:
GET/v2.5/142679255268_10153887281355269
Which returns an object like so:
{
"created_time": "2016-03-25T03:28:50+0000",
"message": "Whats up everybody, I am here now",
"id": "142679255268_10153887281355269"
}
How can I get the profile of the user who posted this?
I have looked through the documentation and couldnt find anything, but I know its possible.
This would work for the Post item:
/142679255268_10153887281355269?fields=from
It returns the following JSON:
{
"from": {
"name": "Bhumi Patel",
"id": "10153245821277822"
},
"id": "142679255268_10153887281355269"
}
More information: https://developers.facebook.com/docs/graph-api/reference/v2.5/post/
Edit: For data privacy reasons, you may not get the name of the user anymore.

Facebook Graph API does not return full post data

I'm using the Facebook Graph API to fetch a public page feed. I created a basic application to get appId and secret. When I make a call to PUBLIC_PAGE_ID/feed I can retrieve the correct list of posts in JSON, but they are missing all the field I need, described in docs, and only have message, created_time and id:
{
"data": [
{
"message": "...",
"created_time": "2015-06-11T07:57:05+0000",
"id": "23X12XXXXXX9836_11XXXXXXXX610XXXX52"
},
...
Why all other data isn't there?
The response to your query: /id/feed is the default response. To access more data, you have to pass a fields parameter with the keyword of data you would like to retrieve.
For example: <id>/feed?fields=id,message,picture,shares
This will return:
{
"data": [
{
"id": "1234567890",
"message": "Message",
"picture": "http://fbcdn.com/xxxxxx.jpg",
"shares": {
"count": 0
}
}
}
What I could figure out is you should submit the app for review with at least one permission what your app still needs and then you will get back every data what you ask in the fields parameter.

Discover SoundCloud user name

I have a SoundCloud client_id that I would like to know the user_id or user name. Actually I have a full link to a track. Is there anyway I can do it?
I think what you're asking is with a track link, find the user_id and username of the uploader of a track.
If you know the full soundcloud.com track URL, hit the /resolve endpoint. For reference, I will be using this URL: https://soundcloud.com/madanofficial/the-police-walking-on-the-moon-j-art-madan-remix
HTTP GET: https://api.soundcloud.com/resolve.json?url=https%3A%2F%2Fsoundcloud.com%2Fmadanofficial%2Fthe-police-walking-on-the-moon-j-art-madan-remix&client_id=[YOUR client_id]
The resulting JSON:
{
"status": "302 - Found",
"location": "https://api.soundcloud.com/tracks/147986343.json?client_id=[YOUR client_id]"
}
When we hit the SoundCloud API again with the /tracks endpoint, just parse the user object that is returned.
"user": {
"id": 44553705,
"kind": "user",
"permalink": "madanofficial",
"username": "Madan.",
"uri": "https://api.soundcloud.com/users/44553705",
"permalink_url": "http://soundcloud.com/madanofficial",
"avatar_url": "https://i1.sndcdn.com/avatars-000098677604-mwg7te-large.jpg?e76cf77"
}