1 00:00:01,400 --> 00:00:02,233 - [Instructor] Once you create 2 00:00:02,233 --> 00:00:03,700 your Twitter developer account, 3 00:00:03,700 --> 00:00:05,960 you will need to get credentials 4 00:00:05,960 --> 00:00:09,000 that you can use to authenticate with Twitter 5 00:00:09,000 --> 00:00:11,760 before you can actually make web service calls 6 00:00:11,760 --> 00:00:15,040 to the various APIs that are available to you. 7 00:00:15,040 --> 00:00:16,630 So what you're going to do 8 00:00:16,630 --> 00:00:18,410 in order to get those credentials 9 00:00:18,410 --> 00:00:20,760 is what they call creating an app 10 00:00:20,760 --> 00:00:22,440 and every app you create 11 00:00:22,440 --> 00:00:25,140 through the developer portal at Twitter 12 00:00:25,140 --> 00:00:27,950 is going to have its own separate credentials 13 00:00:27,950 --> 00:00:31,150 so you can create as many different apps as you like. 14 00:00:31,150 --> 00:00:33,150 Let me switch over to the developer portal 15 00:00:33,150 --> 00:00:34,600 so you'll need to log in 16 00:00:34,600 --> 00:00:36,540 with your Twitter Developer Account. 17 00:00:36,540 --> 00:00:38,120 I'm logged in with ours right now 18 00:00:38,120 --> 00:00:40,280 which is our Deitel Twitter account 19 00:00:40,280 --> 00:00:42,960 and in the drop down menu for our account 20 00:00:42,960 --> 00:00:44,680 that there's an apps option here. 21 00:00:44,680 --> 00:00:47,560 This is where you'll create your app. 22 00:00:47,560 --> 00:00:50,050 Now in my case I've already created a couple of apps. 23 00:00:50,050 --> 00:00:52,140 The one that I'm using for this lesson 24 00:00:52,140 --> 00:00:54,150 is called DeitelTest1 25 00:00:54,150 --> 00:00:56,180 and I'll come back to that momentarily. 26 00:00:56,180 --> 00:00:59,560 You're going to have to click create an app 27 00:00:59,560 --> 00:01:02,530 and once you do you'll have to fill in the required details. 28 00:01:02,530 --> 00:01:04,280 So you need to give your app a name 29 00:01:04,280 --> 00:01:06,360 that's going to be used for example if the app 30 00:01:06,360 --> 00:01:08,410 sends tweets as the sender 31 00:01:08,410 --> 00:01:11,140 or if the app requires a user to log in 32 00:01:11,140 --> 00:01:12,840 with their own Twitter credentials, 33 00:01:12,840 --> 00:01:15,464 this will display the app's name to the user 34 00:01:15,464 --> 00:01:20,040 so that they know what app is requiring those credentials 35 00:01:20,040 --> 00:01:21,240 in the first place. 36 00:01:21,240 --> 00:01:24,300 You must give between ten and 200 characters 37 00:01:24,300 --> 00:01:27,380 of application description information 38 00:01:27,380 --> 00:01:29,339 so for us we just said that we're learning to use 39 00:01:29,339 --> 00:01:31,740 the Twitter API's. 40 00:01:31,740 --> 00:01:34,670 You must supply the website URL for your app 41 00:01:34,670 --> 00:01:37,240 and since we're not actually creating an app 42 00:01:37,240 --> 00:01:38,430 to go and distribute, 43 00:01:38,430 --> 00:01:40,650 we're just demonstrating capabilities 44 00:01:40,650 --> 00:01:44,050 we used our twitter.com URL 45 00:01:44,050 --> 00:01:48,920 which is simply twitter.com/ and whatever your user name is 46 00:01:48,920 --> 00:01:50,900 in our case Deitel. 47 00:01:50,900 --> 00:01:53,760 The other information here is not required 48 00:01:53,760 --> 00:01:55,690 for what we're going to do in this lesson 49 00:01:55,690 --> 00:01:57,740 but if you're creating real apps 50 00:01:57,740 --> 00:02:01,003 you're often going to need to fill in some or all 51 00:02:01,003 --> 00:02:04,540 of this information that you see on the screen right now. 52 00:02:04,540 --> 00:02:06,780 And then finally at the very bottom here 53 00:02:06,780 --> 00:02:10,300 you must fill in a minimum of 100 characters 54 00:02:10,300 --> 00:02:13,410 explaining what the purpose is of your app 55 00:02:13,410 --> 00:02:15,670 in terms of how it's going to be used 56 00:02:15,670 --> 00:02:18,140 and for our purpose we literally just wrote 57 00:02:18,140 --> 00:02:20,110 I am new to Twitter app development 58 00:02:20,110 --> 00:02:22,963 and am simply learning how to use the Twitter API's 59 00:02:22,963 --> 00:02:25,500 for educational purposes. 60 00:02:25,500 --> 00:02:27,459 Now once you fill in the required information 61 00:02:27,459 --> 00:02:30,220 you'll click the create button. 62 00:02:30,220 --> 00:02:32,300 At that point you'll be taken to a page 63 00:02:32,300 --> 00:02:35,020 where you have to agree to the terms 64 00:02:35,020 --> 00:02:36,829 and if you do agree to those terms 65 00:02:36,829 --> 00:02:40,060 you'll click create to actually create your app. 66 00:02:40,060 --> 00:02:41,800 And you can't use the services 67 00:02:41,800 --> 00:02:43,650 until you agree to the terms 68 00:02:43,650 --> 00:02:47,140 so just make sure you check out those terms carefully. 69 00:02:47,140 --> 00:02:49,760 Now once you click create the second time 70 00:02:49,760 --> 00:02:54,320 you'll be taken to a page where you can manage the app 71 00:02:54,320 --> 00:02:55,920 that you just created. 72 00:02:55,920 --> 00:02:58,840 So in my case let me just go to the page for the app 73 00:02:58,840 --> 00:03:00,600 I already have created here. 74 00:03:00,600 --> 00:03:03,260 So that's my DeitelTest1 app. 75 00:03:03,260 --> 00:03:05,860 And it'll look like this at least at the moment 76 00:03:05,860 --> 00:03:10,280 and the important tab for what you're going to need 77 00:03:10,280 --> 00:03:11,690 for your login credentials 78 00:03:11,690 --> 00:03:13,670 is Keys and tokens. 79 00:03:13,670 --> 00:03:16,620 Now I can't show you my Keys and tokens tab 80 00:03:16,620 --> 00:03:20,730 because it has my unique key and token information 81 00:03:20,730 --> 00:03:22,940 that I need to login with my account 82 00:03:22,940 --> 00:03:24,551 and if I give that out to everybody else 83 00:03:24,551 --> 00:03:29,551 then I will probably go past all of the Twitter rate limits 84 00:03:29,570 --> 00:03:32,650 that you are required to adhere to 85 00:03:32,650 --> 00:03:35,270 and I could lose my developer account. 86 00:03:35,270 --> 00:03:37,750 But you're going to click that tab 87 00:03:37,750 --> 00:03:42,750 and on that tab you'll see that there's already information 88 00:03:43,220 --> 00:03:46,650 for your so-called consumer API keys. 89 00:03:46,650 --> 00:03:49,010 And there's two pieces to that information. 90 00:03:49,010 --> 00:03:52,910 There's an API key and an API secret key 91 00:03:52,910 --> 00:03:54,620 and you'll need both of those 92 00:03:54,620 --> 00:03:58,360 so you may wanna copy them down and in fact 93 00:03:58,360 --> 00:04:02,160 you'll want to copy them from the page Keys and tokens 94 00:04:02,160 --> 00:04:05,610 into a file that I'm going to show you in just a moment. 95 00:04:05,610 --> 00:04:09,310 But separately there's going to be another section 96 00:04:09,310 --> 00:04:13,360 to that page and in that section you'll see a create button 97 00:04:13,360 --> 00:04:16,690 for creating what are known as the access token 98 00:04:16,690 --> 00:04:19,150 and the access token secret. 99 00:04:19,150 --> 00:04:22,630 So the API key, the API secret key, 100 00:04:22,630 --> 00:04:25,800 the access token and the access token secret 101 00:04:25,800 --> 00:04:29,850 all four pieces are required for the purpose of 102 00:04:29,850 --> 00:04:32,370 authenticating with Twitter. 103 00:04:32,370 --> 00:04:34,320 Now once you have that information 104 00:04:34,320 --> 00:04:36,640 on your Keys and tokens tab 105 00:04:36,640 --> 00:04:38,520 you're going to want to take it 106 00:04:38,520 --> 00:04:43,140 and put it into this file called keys.py 107 00:04:43,140 --> 00:04:46,920 which you'll find with this lesson's examples 108 00:04:46,920 --> 00:04:49,450 actually this is from the textbook 109 00:04:49,450 --> 00:04:53,730 but it's ch12 examples for these videos, 110 00:04:53,730 --> 00:04:56,040 and you can see we've put in fake values 111 00:04:56,040 --> 00:04:58,320 for a bunch of variables here. 112 00:04:58,320 --> 00:05:00,320 The four that we were just talking about 113 00:05:01,748 --> 00:05:04,570 are the API key, the API secret key, 114 00:05:04,570 --> 00:05:05,780 those are the what we called 115 00:05:05,780 --> 00:05:07,900 consumer key and consumer secret 116 00:05:07,900 --> 00:05:10,890 and then the access token and the access token secret 117 00:05:10,890 --> 00:05:14,660 are the other two pieces of information you needed 118 00:05:14,660 --> 00:05:15,970 to click the create button 119 00:05:15,970 --> 00:05:18,570 for to generate in the first place. 120 00:05:18,570 --> 00:05:20,920 Later on in this lesson we'll also get a key 121 00:05:20,920 --> 00:05:23,642 from the MapQuest mapping API 122 00:05:23,642 --> 00:05:28,642 and you'll insert that value into keys.py as well. 123 00:05:28,740 --> 00:05:31,560 So you're going to want to save that file 124 00:05:31,560 --> 00:05:36,560 and we'll be importing that file into the sessions 125 00:05:36,980 --> 00:05:41,340 that we create and sometimes into scripts as well 126 00:05:41,340 --> 00:05:44,790 so that we have access to those four pieces of information 127 00:05:44,790 --> 00:05:48,360 we need for validating our login. 128 00:05:48,360 --> 00:05:51,840 It's really important that you don't hard code 129 00:05:51,840 --> 00:05:54,460 those values directly into your source code 130 00:05:54,460 --> 00:05:58,690 and that you never give those values to anyone else 131 00:05:58,690 --> 00:06:01,590 otherwise again if you go past the rate limits 132 00:06:01,590 --> 00:06:04,740 that Twitter specifies or you use the service 133 00:06:04,740 --> 00:06:06,400 in any way that's not allowed 134 00:06:06,400 --> 00:06:10,410 your developer account could be terminated in that case. 135 00:06:10,410 --> 00:06:13,910 Now simply separating them into a different source code file 136 00:06:13,910 --> 00:06:16,880 is not particularly secure. 137 00:06:16,880 --> 00:06:21,210 If in fact you are dealing with values 138 00:06:21,210 --> 00:06:23,510 that you really need to keep secure 139 00:06:23,510 --> 00:06:26,140 you probably are going to want to use some sort of 140 00:06:26,140 --> 00:06:28,100 encryption library. 141 00:06:28,100 --> 00:06:31,220 For example one of the popular Python encryption libraries 142 00:06:31,220 --> 00:06:35,460 is called bcrypt, I'll just type the name of it here 143 00:06:35,460 --> 00:06:38,810 so you whoops B-C-R-Y-P-T 144 00:06:38,810 --> 00:06:40,587 so that's the name of the library 145 00:06:40,587 --> 00:06:43,170 and you may wanna use a library like that 146 00:06:43,170 --> 00:06:44,700 for encrypting the data 147 00:06:44,700 --> 00:06:48,280 and storing it in an encrypted manner 148 00:06:48,280 --> 00:06:51,320 on your system and then loading it only as you need it 149 00:06:51,320 --> 00:06:55,180 for shipping it off to Twitter for authentication purposes. 150 00:06:55,180 --> 00:06:58,660 Now all four pieces of that information 151 00:06:58,660 --> 00:07:01,400 are part of what is known as 152 00:07:02,298 --> 00:07:05,570 oauth 2.0 authentication, 153 00:07:05,570 --> 00:07:08,560 and the process of doing that authentication 154 00:07:08,560 --> 00:07:12,240 is handled for you by the Tweepi libraries 155 00:07:12,240 --> 00:07:13,933 as you're going to see shortly.