Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Facebook Graph API to search for an exact string

I want to use the Facebook Graph API to search for exact page matches to "My String".

I tried https://graph.facebook.com/search?q=%22My%20String%22&type=page - but it returns pages that match either "String" or "My".

How do I construct a search query that returns only exact matches to the quoted string?

like image 755
coffee-grinder Avatar asked Jul 18 '12 17:07

coffee-grinder


1 Answers

Currently, you can't. It's triaged on the wishlist.

So, you'll have to wrap the request, in Python :

import requests
query = 'My String'
r = requests.get('https://graph.facebook.com/search?q=%s&type=page' % query)
result = r.json
result['data'] = [ item for item in result['data']
                   if query.lower() in item['name'].lower() ]
print [ item['name'] for item in result['data'] ]

Now you only have exact matches.

like image 138
Maxime R. Avatar answered Oct 30 '22 07:10

Maxime R.