Search autocomplete implementation


#1

Good day!
I’m trying to make Twitter autocomplete hashtag-search in iOS application.
While user is typing I want to show him popular suggestions.
I’ve tried to do it with “GET search/tweets” api method, but it’s just searching through all tweets and not getting me what I want (popular suggestions).
How could I retrieve typeahead suggestions? (like “#iosdev” for “#io” query)
Please help!

Thanks anyway!


#2

Are you using result_type=“popular” on your call to the search/tweets endpoint?


#3

Hello!
Yes, I’m doing exactly that, but it’s not doing the trick.
API always finding tweets with that exact hashtag.

For example:
Search for “#m” popular:
https://api.twitter.com/1.1/search/tweets.json?q=%23m&result_type=popular

Hashtags in result:
M, m, M, M … etc
So Its not possible to use this response as source for autocomplete.


#4

Oh, right, of course!

I don’t think there’s an easy way of finding hashtags to autocomplete with, but maybe you could use the trends endpoints to find popular ones? Not exactly what you are asking for, but I can’t think of a simple alternative right now.


#5

I’ve done it with the following curl command - a similar request will probably work from the iOS app:

curl 'https://twitter.com/i/search/typeahead.json?count=10&filters=true&q=%23cata&result_type=hashtags&src=COMPOSE'


#6

This is not a documented or supported API endpoint and you should not use it. The functionality is not guaranteed, and your application or server may be blacklisted. Please be aware that the Terms of Service state:

You also agree not to misuse our Services, for example, by interfering with them or accessing them using a method other than the interface and the instructions that we provide… [not to] access or search or attempt to access or search the Services by any means (automated or otherwise) other than through our currently available, published interfaces that are provided by Twitter

Thanks for your understanding.


#7

Is there a good reason why there is no official API to support a quality autocomplete/typeahead implementation for both #tags and @mentions?

Anyone who is building a client/app that posts to Twitter needs this. All existing high-profile apps from Buffer to Hootsuite to Adobe Marketing Cloud have each implemented their own ad-hoc version of it, and none of them work quite as expected, because the official API is so limiting. At the end of the day, it’s Twitter reputation that is suffering from these quality of implementation issues.

Simply saying that the undocumented API is not to be used, while acknowledging that there is no other good way to do it is not a proper response for this. Please escalate this to your team and give the people who are eager to build something on your platform reasonably adequate tools.

Thank you for listening.


#8

Thanks for the feedback, you make some great points here which we appreciate.

The reason is one of technical prioritisation. We cannot always provide an API for every feature of the platform and Twitter products - doing so requires significant engineering work, backend sizing, and testing that such endpoints can scale. I can assure you that is definitely something on the list of features that we know developers would like to have.

For more context - at the moment our focus has been on (for example) building new customer service APIs, improving Cards, improving the Wordpress plugin, improving Twitter Kit, adding Ads API features and SDKs, and improving data-related features on the consumption side of the API. We’ve also spent a lot of time in the past ~6 months testing for the extended Tweet changes. All of that work has limited the opportunity to extend the basic APIs, simply from a resource and priority perspective.

On the piece about using undocumented APIs, it is very important not to use them or to rely on them - we don’t offer any kind of support for them and I would not want your apps to be blocked by our antispam systems. I have an obligation to remind you of the terms of service.

Autocompletion may become a target for us to work on in the future, but I’m unable to put any kind of timescale on that right now. I understand that’s likely to be a disappointing answer. It’s up to you to decide whether you feel that’s a “good reason”, but I just wanted to set it against all of the other things the teams here have been working on. Thanks again for adding to the discussion - I appreciate the opportunity to explain a bit more of the background on how things work on the developer platform.


#9

Thank you for the detailed reply, Andy. I do realize that you guys have a lot on your plate and that from time to time you’ll chose to prioritize things differently than some of us would like. My team is also highly appreciative of a lot of the new stuff that you’ve been working on, e.g. extended Tweet changes are simply awesome.

That said, we do hope that you seriously consider bumping the priority for the official autocomplete API; @mentions and #tags autocomplete is a cornerstone of the UX experience of any Twitter app that includes post authoring. Not having proper API support for this raises the complexity of implementing a post editor significantly (to the point that Medium, for example, opted out of implementing autocomplete in their “textshot” post editor altogether), and the end result will still be subpar. If apps like Buffer and Medium are considered to be an important part of the Twitter ecosystem, it seems that you should be able to make a convincing case for prioritizing this.

Thanks again for the quick and detailed reply.


#10

Hi Andy,
Buffer is using typehead search directly in its software for hashtags/mentions search/autocomplete.
Can you, please, confirm if it’s allowed/forbidden to use typehead search in an app? Our customers want this (and tell us that Buffer made a great work to implement it) but you’re telling that using it may cause an app to be blacklisted. Any clarification would be very much appreciated. Thanks!

Best regards,
Serge.


#11

I’m saying that using an undocumented and internal Twitter API endpoint is a violation of the developer policy that you agree to when creating an app on the platform. I have no knowledge of how the services you refer to have implemented typeahead themselves.


#12

I see. Thanks a lot, Andy!

Best regards,
Serge.


#13