Use Facebook API to search for links in posts - php

Hey, I was wondering if it is possible to search Facebook using their API for a given URL. I am trying to find how many people are mentioning a given link.
An example of what I am trying to achieve is the Tweetmeme url_info request but for Facebook. The Tweetmeme API returns an array of imformation about a given link, such as frequency used and last tweeted.
If anyone knows of a Facebook alternative, it would be greatly appreciated. I have a look throught their API wiki but can't find any solutions.
Thanks in advance, Ben

I recently stumblued upon this hidden gem when building an SEO tool:
http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=http://stackoverflow.com/
It's an old API, but you can confirm the counts are up-to-date by checking this against their new Graph API that only gives you the total count:
https://graph.facebook.com/?ids=http://stackoverflow.com/

While researching the answer from Vance Lucas I came accross the FQL equivilent # http://developers.facebook.com/docs/reference/fql/link_stat
$facebook->api_client->fql_query('SELECT share_count, like_count, comment_count, total_count FROM link_stat WHERE url="MY_URL"');
This FQL Statment returns the "Share Count", "Link Count", "Comment Count" and "Total Count".

Check the Graph API Overview page of the Facebook Developers documentation, under the subheading "Searching". It indicates you can use the Graph API to search all public posts for a given query:
https://graph.facebook.com/search?q=<your_url_here>&type=post
(Be sure to URL-encode your URL first.)
This will retrieve a JSON array containing mentions of your URL. It appears not to provide any metadata about the search, but is rather a paginated list of search results, so you'd have to build the metadata yourself.

Related

Get my posts on facebook manage page

I need get ME posts in one of my manage pages, with the new version of facebook sdk.
Example:
I'm manage on Page A, and add a post in my name Adexe Rivera, and in this page there are a lot of posts. So I want to filter only posts by Adexe Rivera.
I know for get posts on pages it's necesary /page/feed, but I need add the filter from user.
I tried with Graph Api Explorer, with this FQL:
SELECT source_id, actor_id, post_id, target_id, message FROM stream WHERE source_id = "PAGE_ID" AND actor_id = "MY_ID"
and get the information that I'm searching.
But I know that since v2.0 FQL not works for sdk, so that I need it's make the same like FQL works in this version of graph
I already tried what documentation said, but not get my posts.
A user access token is required to retrieve posts visible to that person.
Thanks in advance
Filtering is not possible, you can only use the existing endpoints and filter on your own after getting the entries. There are several different endpoints, make sure you are using the correct one. They are all documented very well: https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed
Also, an App Access Token should be enough to get access to the endpoints if it´s a public post on a non-restricted Page:
An access token is required to view publicly shared posts.
If you don´t know about Access Tokens, read those articles:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
Finally, it is not possible to use FQL giving me the expected result, so getting the "from" field in the /PAGEID/feed endpoint, and filtering the results, I get what I wanted.
Thanks for your answers and for their penalties, I have spent several days trying to maximize the performance of the SDK facebook.
Cheers

How do I search for users in Facebook using certain conditions such as location in Graph API

I've been experimenting with the Facebook Graph API, and been researching several questions on Stack Overflow and other internet resources, and I can't seem to figure out how to search users in Graph API and see their location as well (assuming their location is publicly available).
I've looked at:
Facebook Search API - List all users based on location?
PHP Facebook FQL: Making queries in the new SDK
Search for posts using Facebook Graph Api
And although one of them says that you can search for users based on location, I don't think that's correct. But, I was under the impression FQL is no longer supported, as it has been replaced by the Graph API?
Currently I formulate a Graph API URL like the following:
https://graph.facebook.com/search?q=Users_to_Search&type=user&center=47.5700,122.6525&distance=10000&access_token=ACCESS_TOKEN
To try and find users near a certain point, but apparently the "center" and "distance" arguments are simply ignored, and the page merely lists all users that match the query, and only lists their name and ID, not location.
Is there any way to search for users, but only if they're in a certain location? Something like:
SELECT users FROM user WHERE Location="Bremerton, Washington"
Simply put: This is not possible via search afaik. Have a look at the Search API docs here: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search
Also with FQL (which will be available until April 30th 2016), there's no way of doing this.

Facebook search public photos by hashtag

I work with Facebook API SDK. I'm trying to get all public photos using https://graph.facebook.com/search?access_token=xxxx|xxxxx&q=%23hashtag&type=post
But I have a problem: result contains only shared photos in first account. When i'm posting photo without share, search not found it.
Otherwise, I have another account where I'm posted photo and share it, but photo is not found too.
Who knows, how can I get all public photos with hastag using FQL or graph search
Addition:
Few days ago - facebook search is not working
After discussing with facebook developers, I got the answer:
Facebook API does not support searching for hashtags.
%23 is just the URL encoded version of a # which gets decoded on a
server generally so it still won't work. For example if I wanted to
search for #YOLO I would just say q=YOLO with no # or it's URL encoded
form.
It's just something that the api doesn't support at the moment
Facebook has officially deprecated the post search type. Im not sure when exactly but I can tell you I tried today (10/15/2014) and its a no go.

Hashtag search in Facebook API

I am trying to find in Facebook API if they provide the HashTag search.
I meant I search in Facebook Query language and searched in Facebook Tool Explorer.
Any Idea ?
Since April 30th and the introduction of Facebook api v2.0, public Post search is no longer available and will return :
{
"error": {
"message": "(#11) Post search has been deprecated",
"type": "OAuthException",
"code": 11
}
}
According to Facebook changelog v1.0 will continue to work until April 30th, 2015. As the search endpoint is back in the v2 doc, there is hope that they will reconsider the deprecation.
The search endpoint is a fulltext search, you just have to encode the hash (%23) and run your query through it :
Facebook API explorer :
You have to select v1.0 or Unversioned in the API version selector (on the top right)
https://graph.facebook.com/search?type=post&q=%23the_hash_tag
Curl or whatever :
Just remove /v2.0/ from the url and call the unversioned API
https://graph.facebook.com/search?access_token=YOUR_TOKEN&type=post&q=%23the_hash_tag
There is currently no API for the hashtags feature on Facebook
There is a posts search function which will return some posts with a certain hashtag if you use that hashtag as the search string. But it will ignore the # tag.
There is a comment on one of the sites which says "you can change the # with the hex value from the ascii table (%23) to search for hashtags. but it will only find tags, created by the facebook homepage or official facebook applications." Not sure how valid, you could try it
like this https://graph.facebook.com/search?q=%23myhashtag
https://graph.facebook.com/search?q=%23myhashtag
There is no hashtag API available for Facebook and using %23 for #(hash) is the only solution as of now which already everyone here has commented upon.
I'm not too sure about FQL being deprecated in near future as I could see different opinions across the board.
As I am understanding you would use Keyword Insights API
Though as mentioned on the following link
Access to the Keyword Insights API is restricted to a limited set of
media publishers and usage requires prior approval by Facebook. You
cannot apply to use the API at this time.
https://developers.facebook.com/docs/keyword_insights/
Take note on the mention of hashtag searching in the "best practices" section.

Facebook search

I am new to facebook api. I want to search for a particular word on facebook. I have gone through the documentation at https://developers.facebook.com/docs/reference/api/. But I dont know how to construct the query in PHP.
Could any one please provide a sample code. Also how do I specify the count and page (like twitter)?
I am currently using the API provided by facebook. I saw that there are alternative API's but I would like to restrict the API to the official one
Facebook provides the search functionality which is like searching using the search inside facebook.com.
To read about it go to here: http://developers.facebook.com/docs/reference/api/#searching
Edit
As it states in that document:
When searching for public posts or posts on the user's News Feed, you
can page over the results by using the since, until and limit
parameters. since and until both accept a unix timestamp.
Also, just a bit above the "searching" section there's the "Paging" section, using both you can come up with:
https://graph.facebook.com/search?q=coffee&type=place&offset=X&limit=4
Which in terms of using the php sdk, is probably like: "search?q=coffee&type=place&offset=X&limit=4"

Categories