Twitter API, Twitteroauth and get users lookup order - twitter

I use "twitteroauth" and this code fragment:
$userlist='111111,66666,7777,22222';
$Results=$oauth->get( 'users/lookup', array('user_id' => $userlist ) );
After i print out the results, i see that the order of "$Results" is not ok.
For example:
$Results[0] gathers the data of '7777',
$Results[1] gathers the data of '111111'.
I tried this for ten times. Every time the order in array changes.
Is it normal behaviour of twitter API ?
Thank you

Yes this is to be expected. Array order from Twitter is not guaranteed. You will have to use the user_id of each object.

Related

download a list users from twitter

I have a list of "n" Twitter ID representing users I would like to download.
To retrieve their user profile info, should I use n times the api call get_user or there exist a method to pass the entire list and retrieve all the info within one single api call, within the twitter rate time limit?
I tried something like
api.search_users(A)
api.search_users(id in A)
where A contains the list of id
but it does not work.
Anyone helping?
You can use the Twitter API resource https://dev.twitter.com/rest/reference/get/users/lookup. It can return user objects for at most 100 users at a time.
You can use this in Tweepy like:
user_objects = api.lookup_users(user_ids=list_of_at_most_100_user_ids)
Much of this answer first appeared as part of https://stackoverflow.com/a/42946854/1921546

Instagram and iOS. get photo with a lot of likes with current user

I am using Instagram api
My query is
api.instagram.com/v1/users/[USER_ID]/media/recent?count=3818
I get only 33 photos that is ordered by date
But,I need to load all the users photo which has more likes
what am I missing here ?
You can use Pagination.See http://instagram.com/developer/endpoints/ for information on pagination. You need to subsequentially step through the result pages, each time requesting the next part with the next_url that the result specifies in the pagination object.
From instagram
pagination
Sometimes you just can't get enough. For this reason, we've provided a
convenient way to access more data in any request for sequential data.
Simply call the url in the next_url parameter and we'll respond with
the next set of data.
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
} }
On views where pagination is present, we also support the "count"
parameter. Simply set this to the number of items you'd like to
receive. Note that the default values should be fine for most
applications - but if you decide to increase this number there is a
maximum value defined on each endpoint.

How to retrieve hashtaged tweets from a list of users

Is there a way retrieving all the tweets from a list of profiles (3) which are tagged with certain #hashtag in a single call to the Twitter API using 1.1?
If not, obviously, I'd be retrieving a hundred tweets from each user, and filtering out those which do not have the #hashtag .. but it's not very efficient, right?
Thanks in advance
Note: I've updated the library so I suggest you grab the newly updated version before trying this - I've made it so you don't need to manually encode each individual character.
This page shows you how to use search, and has a number of operators down toward the bottom of the page. One of these is the OR operator:
Getting tweets for multiple users
OR - Either this or that
love OR hate - containing either "love" or "hate" (or both)
From - From this user
from:twitterapi sent from the user #twitterapi
So, armed with the above knowledge, I'm guessing your query would look like this:
Translated into a GET request:
?q=from:user1+OR+from:user2
Getting tweets for specific hashtags
So that's how you get tweets for multiple users. The next step you want is for certain hashtags.
#haiku - containing the hashtag "haiku"
That translated individually into the correct format becomes:
?#haiku (or %2C haiku, depending on the library / urlencoding you're using)
Combining the above
The standard AND operator looks like this:
twitter search - containing both "twitter" and "search". Default operator
For a get request:
?twitter+search
So let's combine all this!
?q=#hashtag1+#hashtag2+from:user1+OR+from:user2
And, because you're using my lib, here's the code for that:
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#hashtag1+OR+#hashtag2+from:username1+OR+from:username2';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump(json_decode($json));

Twitter: Number of tweets OR get more tweets

I would like to know how can I get all tweets from a certain hash tag?
I am currently using the following code:
xhr.open("GET","http://search.twitter.com/search.json?q=%23PrayForJapan");
This only returns me 15 tweets. Does anyone know how to make it return more?
Also, I have got a code to get me the tweets of a certain screen name, this only returns 20 tweets, how can i ask the following 20 tweets?
The code i used for that is:
xhr.open("GET","http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Eminem");
I'm using titanium to create this, but I don't think that is an issue?
Thanks!
You can usually add count=x as parameter to the query string to get up to x tweets (for the search api it seems to be rpp). Query string parameters are added to the base url via ? and each individual parameter is then separated by & as in http://api?user=1&count=4
Most of the time, it is better though to remember the last tweets and then add ?since_id=x as this way you only get tweets you did not see before.
Have a look at the api documentation.

Twitter API - Display all tweets with a certain hashtag?

How would I go about displaying tweets that contain a certain hashtag using the Twitter API? Thanks
I'd also like to know if there is a way to get all tweets from a certain hashtag in a separate file, also the ones that don't show up in your feed anymore. I suppose that's what the earlier question was about, too.
This answer was written in 2010. The API it uses has since been retired. It is kept for historical interest only.
Search for it.
Make sure include_entities is set to true to get hashtag results. See Tweet Entities
Returns 5 mixed results with Twitter.com user IDs plus entities for the term "blue angels":
GET http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&with_twitter_user_id=true&result_type=mixed
UPDATE for v1.1:
Rather than giving q="search_string" give it q="hashtag" in URL encoded form to return results with HASHTAG ONLY. So your query would become:
GET https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames
%23 is URL encoded form of #. Try the link out in your browser and it should work.
You can optimize the query by adding since_id and max_id parameters detailed here. Hope this helps !
Note: Search API is now a OAUTH authenticated call, so please include your access_tokens to the above call
Updated
Twitter Search doc link:
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
The answer here worked better for me as it isolates the search on the hashtag, not just returning results that contain the search string. In the answer above you would still need to parse the JSON response to see if the entities.hashtags array is not empty.

Resources