I'm new to Python and need some help. I'm trying to search for historical tweets from 2014 to 2018 from specific Twitter users with specific keywords in a research project and have a few questions for my code.
I can't find a code on how to get the output as a number of tweets instead of a long list of many tweets. Is this possible?
Does anyone know how to connect the endpoint from Twitter Developer to the code? I will use a Premium API account.
I'm getting an Error on the code because of the functions: from and filter, is there a way to fix this? I tried to insert it in the same " " as the query, but that didn't work.
#Endpoint from Twitter Developer
endpoint = 'https://api.twitter.com/1.1/tweets/search/30day/dev.json'
#All keywords
query = 'xxxx' or 'yyyy'
#Search code
search = tweepy.Cursor(api.search, q = query, "from:TwitterUser -filter:retweets", lang = 'en').items()
for item in search:
print (item.text)
And as an additional question not related to my code, is it possible to search for retweets and likes by specific users on certain tweets? Lets say I'm searching for tweets from user1, can I then see how many times user2, user3 and user4 have retweeted and liked user1's tweets?
Thanks for any help!
Cheers
I don't believe that tweepy currently provides support for the premium search endpoints (additionally, I see that your code is hitting a 30 day endpoint, when for your use case you would need to access the full archive search endpoint).
For premium search I would recommend that you look at either TwitterAPI, or the search-tweets-python library that we (Twitter) provide. In the case of the latter, it also supports the counts endpoint, but be aware that these are only available in the paid tier, not the free sandbox. Also, note that the search syntax on the premium search API is different to standard search. Check the documentation.
On your last question unrelated to code - no, there's no API that would enable you to find that information.
Related
I'm trying to get the number of tweets a user has ever liked in NodeJs using twitter-api-v2, but I can't seem to find the solution. I tried to use the "public_metrics" property but it looks like it only contains the following properties:
followers count
following count
tweet count
listed count
I also tried to use the client.v2.userLikedTweets() method but it can only go up to 100 likes, I know I could upgrade to a premium account but I don't want to
Is there a solution? Thanks.
If you have an elevated access, you can use the favourites_count field in the User objects from the Twitter API V1. But there is unfortunately no way to do so with the Twitter API V2.
The media:search endpoint is okay, but I really need a keyword search. Just like the actual website has. i.e. football
I've tried using the Google Custom Search API and pointing it to photos.google.com, but that is unable to get past the login screen even though I'm authenticated.
Anyone else have any workarounds for a keyword search?
Keyword search is currently not supported in the Google Photos Library API.
There's a feature request on the issue tracker that you can star to draw attention to it and be notified of updates: https://issuetracker.google.com/110300471
At the moment you can search the library by what's in the photo ("content categories"), dates, media types and archived state. More information about what's currently supported is in the developer documentation: https://developers.google.com/photos/library/guides/apply-filters
I have a domain which have a feature to login with instagram a/c, registered users associate their instagram a/c using this process.
Now i want to store/save all post and comments of users they have posted on instagram a/c.
So that i can perform a search on comments and caption of posts.
As fas as my knowledge its not possible by using instagram api thats why i am saving info in my database.
Is there any simple way to perform search ?
Any help will be appreciated.
Thanks
Instagram only gives you 150 latest comments via API, so if you want to search through all comments, you have fetch comments at regular interval and save on server, searching these comments are straight forward, look for substring in the comment items saved. It is kind of tricky on deciding how often you want to check for comments and store, usually mosts comments are posted few minutes after a popular photo is posted. If you do the checks too often, you may reach the API rate limit.
https://api.instagram.com/v1/media/{media-id}/comments?access_token=ACCESS-TOKEN
If you are dealing with less than 150 comments on average, then you can search through it without needing to save on server and can be done all on client side. Just pull the comments using API and do search through the array of comments using javascript.
Picodash allows you to view the latest 150 comments and search any keyword or user, here is screenshot:
I have developed library in php: https://github.com/raiym/instagram-php-scraper
It allows you to get ALL comments from specific post (I have tested with 8 000 comments)
$comments = Instagram::getMediaCommentsByCode('BGY0zB4r7X2', 1500);
I am using node.js(Meteor) for calling Amazon MWS ListMatchingProducts API for getting all products of my seller account . Its running sucessfully and i am getting the response , but as the documentation said that only ten(10) products are returned at one time. So i just want to know how we get products more than 10 . In the doc Amazon also said that you can submit NextToken with a "ByNextToken" operation to request additional pages.But i am not getting any nextToken or related to that nextToken field on my response.So how do i get the nextToken from there side or how can i get more than 10 products from that API. As i also check on one post they said that we need to use Reports for that but i want to use ListMatchingProducts API for that and want result more than 10.
Please provide me any suggestion or guidance how can i achieve that.
Any help would be appriciated
Thanks
You want to call the Reports API using the Inventory Report report type or one of the other Listing Report types. That is the way to go. The ListMatchingProductsoperation of the Products API is meant to be a search, based on a query. Yes, it only lists ten products but it does not give you a NextToken like some of the other operations. Knowing your Report Type and Marketplace ID, you can submit those to the Reports API with your credentials and get back all of your products all at once and there is no searching involved.
What I would also suggest is to use the Amazon Scratchpad to play around with your operations to make sure you get what you expect, then plug it into your node.js project.
I've searched through the topics but it seems that exactly this questions hadn't been asked yet.
Could anyone, please, share their opinion on how to retrieve an Instagram account followers' posts locations in order to map them after that on one map?
On the account there are around 2000-2100 followers.
Thank you in advance!
To get detailed user information from instagram you have to use the GET /users/user-id endpoint.
So to get the location information for all an accounts followers you have to use
GET/users/user-id/followed-by and iterate through the results.
Be careful. Instagram api limit is currently 5000 requests per hour. Accounts with more followers than that you will have to use some form of queue
Edit: just seen you want the post locations:
Similar method, excite instead of GET /users/user-id user GET /users/user-id/recent and grab the locations of the media. Note in my experience the location function is used very little by instagram users. I once pulled 3000 media that had only 20 media with a location
You cannot just location of a user using APIs, there are couple ways you can guess the location, by looking for bio information and check if they have any location specified or you can check location of all the photos posted by a user and kind of guess the location by analyzing where most of the photos are being posted at.
you can use the API /users/user-id/recent to get all the photos from a user and look for location property in API response and map it on google map.
you can use http://gramfeed.com to see user photos with a map of photo locations, you will have to do this for each user and determine the location.