- [Instructor] Once you create
your Twitter developer account,
you will need to get credentials
that you can use to authenticate with Twitter
before you can actually make web service calls
to the various APIs that are available to you.
So what you're going to do
in order to get those credentials
is what they call creating an app
and every app you create
through the developer portal at Twitter
is going to have its own separate credentials
so you can create as many different apps as you like.
Let me switch over to the developer portal
so you'll need to log in
with your Twitter Developer Account.
I'm logged in with ours right now
which is our Deitel Twitter account
and in the drop down menu for our account
that there's an apps option here.
This is where you'll create your app.
Now in my case I've already created a couple of apps.
The one that I'm using for this lesson
is called DeitelTest1
and I'll come back to that momentarily.
You're going to have to click create an app
and once you do you'll have to fill in the required details.
So you need to give your app a name
that's going to be used for example if the app
sends tweets as the sender
or if the app requires a user to log in
with their own Twitter credentials,
this will display the app's name to the user
so that they know what app is requiring those credentials
in the first place.
You must give between ten and 200 characters
of application description information
so for us we just said that we're learning to use
the Twitter API's.
You must supply the website URL for your app
and since we're not actually creating an app
to go and distribute,
we're just demonstrating capabilities
we used our twitter.com URL
which is simply twitter.com/ and whatever your user name is
in our case Deitel.
The other information here is not required
for what we're going to do in this lesson
but if you're creating real apps
you're often going to need to fill in some or all
of this information that you see on the screen right now.
And then finally at the very bottom here
you must fill in a minimum of 100 characters
explaining what the purpose is of your app
in terms of how it's going to be used
and for our purpose we literally just wrote
I am new to Twitter app development
and am simply learning how to use the Twitter API's
for educational purposes.
Now once you fill in the required information
you'll click the create button.
At that point you'll be taken to a page
where you have to agree to the terms
and if you do agree to those terms
you'll click create to actually create your app.
And you can't use the services
until you agree to the terms
so just make sure you check out those terms carefully.
Now once you click create the second time
you'll be taken to a page where you can manage the app
that you just created.
So in my case let me just go to the page for the app
I already have created here.
So that's my DeitelTest1 app.
And it'll look like this at least at the moment
and the important tab for what you're going to need
for your login credentials
is Keys and tokens.
Now I can't show you my Keys and tokens tab
because it has my unique key and token information
that I need to login with my account
and if I give that out to everybody else
then I will probably go past all of the Twitter rate limits
that you are required to adhere to
and I could lose my developer account.
But you're going to click that tab
and on that tab you'll see that there's already information
for your so-called consumer API keys.
And there's two pieces to that information.
There's an API key and an API secret key
and you'll need both of those
so you may wanna copy them down and in fact
you'll want to copy them from the page Keys and tokens
into a file that I'm going to show you in just a moment.
But separately there's going to be another section
to that page and in that section you'll see a create button
for creating what are known as the access token
and the access token secret.
So the API key, the API secret key,
the access token and the access token secret
all four pieces are required for the purpose of
authenticating with Twitter.
Now once you have that information
on your Keys and tokens tab
you're going to want to take it
and put it into this file called keys.py
which you'll find with this lesson's examples
actually this is from the textbook
but it's ch12 examples for these videos,
and you can see we've put in fake values
for a bunch of variables here.
The four that we were just talking about
are the API key, the API secret key,
those are the what we called
consumer key and consumer secret
and then the access token and the access token secret
are the other two pieces of information you needed
to click the create button
for to generate in the first place.
Later on in this lesson we'll also get a key
from the MapQuest mapping API
and you'll insert that value into keys.py as well.
So you're going to want to save that file
and we'll be importing that file into the sessions
that we create and sometimes into scripts as well
so that we have access to those four pieces of information
we need for validating our login.
It's really important that you don't hard code
those values directly into your source code
and that you never give those values to anyone else
otherwise again if you go past the rate limits
that Twitter specifies or you use the service
in any way that's not allowed
your developer account could be terminated in that case.
Now simply separating them into a different source code file
is not particularly secure.
If in fact you are dealing with values
that you really need to keep secure
you probably are going to want to use some sort of
encryption library.
For example one of the popular Python encryption libraries
is called bcrypt, I'll just type the name of it here
so you whoops B-C-R-Y-P-T
so that's the name of the library
and you may wanna use a library like that
for encrypting the data
and storing it in an encrypted manner
on your system and then loading it only as you need it
for shipping it off to Twitter for authentication purposes.
Now all four pieces of that information
are part of what is known as
oauth 2.0 authentication,
and the process of doing that authentication
is handled for you by the Tweepi libraries
as you're going to see shortly.