Twitter username autocompletion - twitter

I would like to allow users on my website to nominate other Twitter users in a text input field. I intend to provide an autocompletion feature similar to Twitter's mention typeahead when a user enters # in a Tweet.
#JakeHarding developed similar functionality in a demonstration of typeahead.js. Unfortunately, the logic is hidden in a herokuapp.
I would be grateful for any support you can provide.

Looking at the response from typeahead-js-twitter-api-proxy.herokuapp.com it's just a proxy for GET users/search. So just set up a server that takes the auto-complete text, wraps it in OAuth, and forwards it to the Twitter API. You'll have to be very mindful of rate limits though. Autocomplete will burn through that in no time.

Related

Beginner Question: How to access the number of impressions from *other users'* tweets?

I've got a bunch of free online HTML, CSS, and JS tutorials under my belt and I want to try using them to make a browser extension. But I want to make sure that the data I want to use is actually accessible before getting started.
My goal is to make a browser extension for twitter.com that shows the number of impressions of any tweet next to the likes, retweets, and replies. My basic idea is to get the status URL of any given tweet, poll the Twitter API for the number of impressions of that tweet, store that in a variable, and then use CSS to display a little eye icon and the number stored in the impressions variable.
I know that I can find the number of impressions of all of my tweets, both through Twitter Analytics, and also just going to my profile page and clicking the little bar chart icon next to views, retweets, etc. But I'm not clear on whether I can do that for other people's tweets via Twitter's API or anything else. Can you?
For the record, I'm not too concerned about the varying definition of "impression," since it will be consistently applied across all tweets and I'm mostly interested in giving users a comparison between tweets. This is part of a research project to see how this might change how people engage with social media if they know how many views a given post has. If there's a simpler way to go about that using existing platforms, I'm open to suggestions.
Thanks for the advice!
No, impressions data is private. If you are authenticated to the Twitter API then you can use the new Twitter Developer Labs Tweets API to get private metrics like impressions, but you cannot get that for other people's Tweets. Also, the Twitter API does not support CORS, so I don't think you'll be successful trying to use it from a browser extension.

Building a Twitter Search Box With Search Suggestions

I am developing a site that is integrated with Twitter content and I would like to enhance my search box providing search suggestions for hashtags and handles as the user types. Is there any way to get this autocomplete data generated from Twitter?
thanks().InAdvance();
There isn't anything in the Twitter API that does that. Besides, it wouldn't work either because the rate limits would never permit that type of interaction. e.g. you might have n queries in a 15 minute window. If you eat up that much rate limit, it leaves less to iterate through the rest of the results an support subsequent queries, leaving the user waiting until the next 15 minute window. I understand what you want to do, but 3rd party APIs, like Twitter, have very specific pre-defined functionality and don't work like a general purpose database.

Custom user tracking or 3rd party service for page referral analytics

The question I'm trying to answer for a set of users is how other users end up on their page. There are about 5 different ways a user can end up on your page. For example, they could have searched your name, clicked a link from a newsfeed or received an e-mail with a link to your page.
What is the best way to accomplish tracking these events? I'm initially inclined to create a table to track this. Each link would send an async event to the server to be added to the table. However, I'm also aware that there are many tracking services out there such as Google Analytics and Mixpanel. I've looked at their docs briefly and they don't seem to fit my need.
Am I missing something? Is it worth it to create a "custom" even tracking system to accomplish this?
It is not worth creating your own service. Plus you cannot add async link to search engine result pages or emails (that would require tracking code that you cannot implement in search engines or that would not be executed in mail clients).
Web analytics software tracks traffic sources by analyzing the incoming traffic via its http headers. If there is a referrer set the traffic will be attributed to, well, the referring site, unless the traffic is included in a list of known search engines in which case it will be attributed to organic search traffic etc.
In most systems you can customize source attribution by adding query parameters in the url (obviously this will not work with search engines and the like, since you cannot add parameters to organic search results). For example with Google Analytics you can add custom campaign parameters in email links or advertising campaigns. If people click on those links the parameter value will be send to GA and the source/medium/campaign information will be set accordingly (e.g. traffic from web mail clients would usually be attributed as a referrer, but campaign parameters allow to attribute the link to your mail campaigns).
There might be reasons to create your own system, but channel attribution is not one of them; GA and every other system I know of has this thoroughly covered.

How do I know if a specific twitter user is online or not?

How do I know if a specific twitter user is currently online by writing programs? Is there any API or data field in the web page showing this information? Both browsing Twitter webpage and using Twitter app are considered "online".
Although this information is not readily available, you can do a work around. Make use of Twitter's Streaming API: https://dev.twitter.com/docs/streaming-apis/streams/public (have a read through this document).
You'll most likely be using the POST Statuses/filter functionality (read the doc here: https://dev.twitter.com/docs/api/1/post/statuses/filter ), which will give you a JSON object with tweets based on your filters.
Make use of the parameters you'll need to specify in the URL to filter the stream (have a look through this document to learn more about it: https://dev.twitter.com/docs/streaming-apis/parameters ), in your case it'll be the follow parameter. You basically specify the twitter ID of the user you want to follow. Here's a sample JSON result of the streaming API in action https://stream.twitter.com/1/statuses/filter.json?follow=25365536 - this one in particular is following Kim Kardashian. Keep in mind that this will give you:
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
So in order to just stream the tweets of your desired user, you'll have to use a programming language of your choice to parse through the JSON object to find the user that actually sent the tweet (this is a little tricky, you'll have to look through the properties of the JSON object to figure it out). Once you narrow the streaming tweets to just the ones from the user though, you can then have an alert on when new tweets by this user stream and that will tell you if the user is online/using twitter at the moment.
It's not clear what you mean by "online" (browsing twitter.com? Using a Twitter app?), but in any case Twitter doesn't provide such information, thankfully.
I'm afraid such information is limited by Twitter and is not available. However you can put your question on https://dev.twitter.com/discussions and ask its developers. Good Luck
you need get user state first
then filter if around current time
then get ids
they are online
use twitter developer api
I do it for my website

What is the best way to embed a user's tweets and mentions into a website?

I need to embed a specific user's recent tweets onto the home page of a website. The website is built in ASP.NET.
I've looked at the Twitter REST API and have tried using the user_timeline. It works but does not include mentions for the user. I want to include mentions but the only way to do it seems to be by using APIs that require authentication. I would prefer not to use authentication as it seems it would start to make things more complicated. I also do not want to get the current user to authenticate.
What is the best way to achieve this?
Use the GET search API instead. Search for statuses containing the user's #username, but in this case it will not return mentions from private/locked accounts since there's no authentication.
For example, if you want to search mentions for #stackexchange, call this.
GET http://search.twitter.com/search.json?q=#stackexchange
You could do a search for #username using the REST Search api. There's a good chance that would work :)

Resources