How to use premium API for the first time (beginner)?


#3

Hey Ross! This is unrelated, but how long did it take for twitter to approve your premium API request? I am conducting similar work and I’m anxious to get my hands on my data asap but I havent been approved yet.

Also - good luck with your research!


#4

I applied on a Monday and was approved on a Friday. Good luck!


#5

How do I connect my Premium account to one of the apps I’ve created? I tried to link them on the dev environments, but it didn’t seem to work. When I access the API, it still acts as if it was a basic version and not the premium. Any tips?

Thanks again!


#6

If you see the app’s name linked in the Dashboard (https://developer.twitter.com/en/account/environments) then it should be set. What errors are you seeing that lead you to believe there’s an issue?

There are code samples on this page that may help you.


#7

I do not have much experience with Python, so this is all a bit confusing for me since most of the available documentation is geared for experienced developers, and not beginners. I have viewed the documentation and all the links you’ve sent me, but it still doesn’t seem to work. I sat today for about 3 hours with a friend who does Python, and we still can’t get it to work. Is there not simply one example code available, where I can copy/paste my unique credentials and then perform the desired query?


#8

You can try using one of the simple command-line examples, for instance:

curl --http1.1 --request POST  
--url https://api.twitter.com/1.1/tweets/search/30day/YOURENV.json 
--header 'authorization: Bearer YOURTOKEN'  --header 'content-type: application/json' 
--data '{"query": "andypiper has:images","maxResults": 20}'

Your token can be generated using this script if needed.


#9

Hi, i am in the same situation as Ross… Providing some full working examples could really help to work with R or other products.


#10

Hi Ross,

# minimum example for R

install.packages("httr")
install.packages("base64enc")
library("httr")
library("base64enc")

appname <- ",,,"
key <- "..."
secret <- "..."

# base64 encoding
kands <- paste(key, secret, sep=":")
base64kands <- base64encode(charToRaw(kands))
base64kandsb <- paste("Basic", base64kands, sep=" ")

# request bearer token
resToken <- POST(url = "https://api.twitter.com/oauth2/token",
                add_headers("Authorization" = base64kandsb, "Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"),
                body = "grant_type=client_credentials")

# get bearer token
bearer <- content(res)
bearerToken <- bearer[["access_token"]]
bearerTokenb <- paste("Bearer", bearerToken, sep=" ")

# get example from full archive
resTweets <- POST(url = "https://api.twitter.com/1.1/tweets/search/fullarchive/LIVE.json",
            add_headers("authorization" = bearerTokenb, "content-Type" = "application/json"),
            body = "{\"query\": \"andypiper has:images\",\"maxResults\": 20}")

tweets <- content(resTweets)

Premium APIs with R
I can't get old tweets having "Premium - Search Tweets: Full-archive endpoint"
Premium API endpoint
Premium API with R?
#11

@andypiper can you please explain how this even possible? 5 days? People are waiting for months but some however are getting just in one week!


#12

I’m sorry, but we are unable to comment on individual requests for access to the APIs. We appreciate your patience.


#14

As applications for the beta come in, we are doing our best to quickly process those that have a well defined use case and explain how they plan to use the APIs. Those that don’t match those criteria often require email correspondence, to understand what it is you are actually trying to do with the API, which takes us time.

Hang in there - I know this is not ideal and we are working to expedite the process.


#15

Let me know if i can help to create some examples for R like above. :slight_smile: Glad to help


#16

That’s a great offer @hupseb thank you - we don’t have deep experience in R on the @TwitterDev team so community contributions are welcomed. If you’d like to work with the existing library author for rtweet to offer premium search and/or account activity support then I’m sure they would welcome it; if you put any of your own code on Github to help others, I’ll be sure to make sure that the community is aware!


#17

That would be wonderful, @hupseb!


#18

Hi Andy,

Another quick question: is there a way to collect a sample when searching the twitter archives? For example, if I want to look at tweets from one week, is there a way to take a random sample from that time period? Or will the API just return tweets in chronological order?

Thanks!


#19

There is a sample operator - but it is only available in the historical and realtime streaming PowerTrack API, which is an enterprise product. There’s no way to achieve this via the premium search APIs.


#20

I am also looking at tweets for my M.A. thesis using R. Thank you for posting this.
Would you mind explaining what is going to in your “get example from full archive”. I set the url to https://api.twitter.com/1.1/tweets/search/fullarchive/my_env_name.json and in the body instead of andy piper I put my application name. Should I be application name or the name of the person whose tweets I am trying to retrieve? Either way I end up getting a list of length 3 which I don’t understand what I am supposed to do with.

NOTE: I am trying to get tweets of specific people during specific period of time.


#21

Hi all.
Browsing through all Premium API topics, I could not find any suitable title other than this. So… may I ask my newbie question? I already worked standard search API over a year or so with one appplication registered at https://apps.twitter.com/ . Upon my approval as premium API user, https://developer.twitter.com/en/account/get-started tells me to “Create an app.” Should I create another app for premium API or can I user already registered app (and its keys) for premium API use? I guess I need to create a new one, but to be clear, would someone kindly tell me? :smile:

Edit: Can I use my application from apps.twitter.com? seems to relate to my question, but it is not clear if a new app is needed or desirable, or it is not always necessary.


#22

You can use an existing app, or create a new one and associate it with your new development environment on the developer dashboard. When you create a new dev environment, you get to choose a label for the environment, and choose an app from a drop-down list of all of the apps associated with your account.


#23