Twitter API - Search latin special characters - twitter

How can I perform a search in Twitter API that matches with special chars like Ñ or Ç?
Even web search seems to be confused with those characters
Ex:
https://twitter.com/search?q=u%C3%B1as&src=typd
It returns a list of tweets matching with 'unas' and 'uñas', and the same result is returned if an API search is performed
And it happens in inverse way, if you search 'barca' twitter will return tweets matching with 'barça' and 'barca'
The only way I found to ensure that the keyword, and only the keyword, is in tweets, is a programming filtering when results are fetched. Is there any better way?

Related

Escaping parentheses in contact search API

I am trying to search for a contact with a phone number of the following format:
(XXX) XXX-XXXX
I tried the following query and get no results:
/v1.0/me/contacts?$top=10&$search="(XXX) XXX-XXXX"
I also tried it with URL encoded parenthesis and also get no results:
/v1.0/me/contacts?$top=10&$search="%28XXX%29 XXX-XXXX"
The only thing that worked for me is:
/v1.0/me/contacts?$top=10&$search="*XXX*XXX*XXXX"
However, with the last one I'm concerned that it could return bad results in some cases where there might be some other numbers in the wildcard positions.
Is there a proper way to do this search?
Have you considered using filter query instead of search, that way you might be able to scope the search just to the phone field.

How to track and stream tweets for keywords with AND operator using phirehose library?

I am trying to connect to streaming API of twitter and retrieve tweets keywords using specific keywords. I am using the phirehose library for the same. It says in the twitter documentation that "commas as logical ORs, while spaces are equivalent to logical ANDs (e.g. ‘the twitter’ is the AND twitter, and ‘the,twitter’ is the OR twitter)."
But I want to search for keywords with AND operator even if there are other words in between. Meaning if we want to search for tweets having Keyword1 AND Keyword2, tweets which have only one keyword should not be retrieved.
Using the settrack function of the phirehose library -
setTrack(array('the , twitter'));
retrieves tweets with either the OR twitter while
setTrack(array('the twitter'));
retrieves tweets with the phrase the twitter and does not retrieve tweets like the busy twitter for example.
Please help.
140dev by Adam Green gives a solution for this by using ``typeenum('words','phrase') NOT NULL DEFAULT 'words'
Please see - http://140dev.com/twitter-api-programming-blog/streaming-api-enhancements-part-2-keyword-collection-database-changes/ and
http://140dev.com/twitter-api-programming-blog/streaming-api-enhancements-part-3-collecting-tweets-based-on-table-of-keywords/

Tweepy: Search in stream api

In Tweepy api for twitter I know we can search tweets by -
api.search(q="a and b")
Here it will search for both a and b appearing anywhere in the status in any order. However I need to do same for the Tweepy stream api, Is there any way to do that?
I know there is track field -
stream.filter(track=['a','b'])
But this would return status containing either of a or b, I need both of the keywords in any order.
We could also do like, search for only a then manually filtering out status which contain b, but then we would be discarding huge no. of tweets as stream api gives only 1% of the tweets
Yes, this can be done easily. Looking at the docs for the Twitter API track paramenter:
A comma-separated list of phrases which will be used to determine what Tweets will be delivered on the stream. A phrase may be one or more terms separated by spaces, and a phrase will match if all of the terms in the phrase are present in the Tweet, regardless of order and ignoring case. By this model, you can think of commas as logical ORs, while spaces are equivalent to logical ANDs. For example, ‘the twitter’ is (the AND twitter), and ‘the,twitter’ is (the OR twitter).
By this logic, to filter by a and b:
stream.filter(track=['a b'])

Search results in Twitter API dont match Twitter website search results

I am using REST API to extract twitter search results in Hindi and Hebrew.
Search phrase in Hindi - "मुझे सपना आया" OR "मैंने सपना देखा की"
Twitter search results return about 100 results for this phrase - https://twitter.com/search?src=typd&q=%22%E0%A4%AE%E0%A5%88%E0%A4%82%E0%A4%A8%E0%A5%87%20%E0%A4%B8%E0%A4%AA%E0%A4%A8%E0%A4%BE%20%E0%A4%A6%E0%A5%87%E0%A4%96%E0%A4%BE%20%E0%A4%95%E0%A5%80%22%20OR%20%22%E0%A4%AE%E0%A5%81%E0%A4%9D%E0%A5%87%20%E0%A4%B8%E0%A4%AA%E0%A4%A8%E0%A4%BE%20%E0%A4%86%E0%A4%AF%E0%A4%BE%22
However Twitter explorer console API (https://dev.twitter.com/console) returns only 1 result.
Same thing happens for the Hebrew phrase as well. Website returns correct results. API only returns 1 result
Search phrase in Hebrew - "אתמול בלילה חלמתי"
Please Help!!
Thanks,
DB
Found out that for Twitter search api results only go back 1 week for exact phrase matches versus keyword matches. So changed my search criteria from exact phrases to separate words to solve the problem.
Here are the links from Twitter discussions which I found related to this topic.
https://dev.twitter.com/discussions/20596
https://dev.twitter.com/discussions/23726
When I try to console (With OAUTH) it returns more than 1 result.
If it doesn't for you try to make the count value higher.
this is my result:
http://pastebin.com/H2HVs71G
-Tim

Youtube API automatically filters out "alphabet/number-added to search string"?

Let's say I search Youtube API for "Metric"
But I don't want search results like "econometrics" "metrics"
So I mean NO alphabet or number should be added to the left or right to the search string.
A space can be put to the left or right to the search string, like "Fun Metric course".
I was thinking about this.
But interestingly, when I search Youtube website (not API), if I search for "Metric", then only search results with "Metric" but no "econometrics" are displayed.
Another example: If I search for "microecon", then no search results with "microeconomics" are displayed.
Does Youtube website automatically filters out such words (like econometrics which have alphabets added to original search string "metric") even if I don't ask it to do so?
Similarly, does Youtube API (NOT website) automatically filters out such words (like econometrics which have alphabets added to original search string "metric") even if I don't ask it to do so??
It may be different for api version 3, but the documentation only refers to "The q parameter specifies the query term to search for".
But there is some brief documentation for this q paramter in api version 2.
See:https://developers.google.com/youtube/2.0/reference#qsp
Since it's very brief, here it is also:
The q parameter specifies a search query term. YouTube will search all video metadata for videos matching the term. Video metadata includes titles, keywords, descriptions, authors' usernames, and categories.
Note that any spaces, quotes or other punctuation in the parameter value must be URL-escaped.
To search for an exact phrase, enclose the phrase in quotation marks. For example, to search for videos matching the phrase "spy plane", set the q parameter to %22spy+plane%22.
Your request can also use the Boolean NOT (-) and OR (|) operators to exclude videos or to find videos that are associated with one of several search terms. For example, to search for videos matching either "boating" or "sailing", set the q parameter to boating%7Csailing. (Note that the pipe character must be URL-escaped.)
Similarly, to search for videos matching either "boating" or "sailing" but not "fishing", set the q parameter to boating&7Csailing+-fishing.

Resources