1
00:00:05,360 --> 00:00:10,377
At the end of the last video, I mentioned that we
could do something more useful with our shopping list. 

2
00:00:10,377 --> 00:00:15,200
If we just print it out, our cooks will have
to write the list down before they go shopping.

3
00:00:15,200 --> 00:00:20,588
If we store it in some kind of data structure, as
we've done, we could do something more exciting with it. 

4
00:00:20,588 --> 00:00:24,480
So in this video, I'm going to demonstrate
something more exciting. Now I'm not going to show

5
00:00:24,480 --> 00:00:31,840
you the code for this, nor will I make it available
in the resources for this video. This is purely a

6
00:00:31,840 --> 00:00:36,880
demonstration of what's possible. At this point
in the course, you haven't learned enough to be

7
00:00:36,880 --> 00:00:43,760
messing with your Google accounts. It's possible, if
you attempt too many logins too quickly, or get the

8
00:00:43,760 --> 00:00:48,800
authentication wrong, that Google will lock you out
of your account. Now of course, if you're using an

9
00:00:48,800 --> 00:00:54,240
iPhone that wouldn't bother you as much, but if
your main phone is an Android device, then being

10
00:00:54,240 --> 00:00:59,440
locked out will be inconvenient, to say the least.
Now another reason I won't be making this code

11
00:00:59,440 --> 00:01:08,480
available, is that it uses an unofficial API. We'll
see the demo, and then I'll talk a bit about APIs.

12
00:01:08,480 --> 00:01:13,600
Alright, so I have to run this demo from a terminal,
rather than from Intellij's Run pane, and that's

13
00:01:13,600 --> 00:01:20,759
because we're using the Python getpass module.
I'll quickly go to a browser - we'll check that out.

14
00:01:22,160 --> 00:01:27,840
Now the getpass function is similar to input,
but it doesn't echo the input to the console.

15
00:01:27,840 --> 00:01:32,640
If you used the input function here, my username
and password would be visible on the video, which

16
00:01:32,640 --> 00:01:38,400
obviously, isn't a good thing. If you use getpass
in your code, be aware that it doesn't work in the

17
00:01:38,400 --> 00:01:44,560
Intellij Run pane. It does, however, work in the
Intellij terminal, as well as a normal terminal

18
00:01:44,560 --> 00:01:48,720
and Windows command prompt. Alright,
so swinging back to the code again.

19
00:01:48,720 --> 00:01:55,088
Alright, so I'm going to open the terminal. I'm going
to right click up here, and select Open in terminal.

20
00:01:55,440 --> 00:02:02,720
And make sure that's set up to go to the right;
Move to, Right Top, and what I'm going to do, 

21
00:02:02,720 --> 00:02:09,919
is simultaneously now, start recording on my Android
phone. Alright, so you can see my recorder on

22
00:02:09,919 --> 00:02:15,200
screen now - the Android screen, and I go into
my keep notes app which is part of Android.

23
00:02:15,200 --> 00:02:18,480
And you can see at the moment, we've got no
notes showing there, and what I'm going to do

24
00:02:18,480 --> 00:02:24,320
is leave that open while we're running this. Next
thing I'm going to do from our terminal session,

25
00:02:24,320 --> 00:02:31,840
is type python meal_planner -
we get rid of this little prompt here -

26
00:02:31,840 --> 00:02:34,441
planner.py.

27
00:02:35,360 --> 00:02:44,960
Now I'm going to use the same options we've used
previously; four, two, five and then zero. 

28
00:02:44,960 --> 00:02:50,000
So I've finished choosing the recipes, and I've exited the
program. Next you can see what it's asking for, 

29
00:02:50,000 --> 00:02:57,086
is it's asking me to log in to my Google account.
I'm going to type in my username and password

30
00:03:01,440 --> 00:03:06,400
If I've got it right, we keep watching the screen,
you should see that we get a message that it's

31
00:03:06,400 --> 00:03:09,789
been added - it's added some things -
and looking at our notes app,

32
00:03:09,789 --> 00:03:14,240
you can see what happened there in real time.
The Shopping List was created on my mobile phone.

33
00:03:14,240 --> 00:03:19,680
So I've got the items that I need, transferred
from our Python application, to the phone. So this

34
00:03:19,680 --> 00:03:26,320
time what I'll do, is I'll close down our notes
application. I'm going to run the program again.

35
00:03:26,320 --> 00:03:31,200
This time I'm going to choose option 6: Spam a la tin.

36
00:03:31,200 --> 00:03:37,902
And you can see that there's two options
there; tin opener and a spoon that we need - zero to exit.

37
00:03:38,480 --> 00:03:45,840
I need to log in again, paste
that in and enter the password.

38
00:03:49,440 --> 00:03:54,160
So we've got that added now, and if we go back to
our Android application. And you saw what happened

39
00:03:54,160 --> 00:03:59,680
when I opened  it - we got those two extra items
appear; the tin opener and the spoon. So that's

40
00:03:59,680 --> 00:04:05,520
really cool. I can now check off the things I buy,
but it wouldn't be hard to use the same API to

41
00:04:05,520 --> 00:04:11,840
read the note and update our pantry, with the items
bought. Microsoft have published an API for OneNote,

42
00:04:11,840 --> 00:04:16,880
allowing you to use that instead of Google Keep,
if you prefer. There's also a Google Drive API, 

43
00:04:16,880 --> 00:04:21,360
if you want to create a document on Google Drive and
open that on your phone. A bit of googling will find

44
00:04:21,360 --> 00:04:30,800
APIs for Evernote, and the Apple iCloud as well. So
what exactly is an API? Well API is an acronym for

45
00:04:30,800 --> 00:04:36,480
Application Programming Interface. It defines the
objects and functions that are made available, 

46
00:04:36,480 --> 00:04:42,240
and how to use them. We've already used a lot of APIs
in this course. For example, we used the list API

47
00:04:42,240 --> 00:04:46,960
when we worked with lists. The documentation
described the list object, and the methods

48
00:04:46,960 --> 00:04:53,920
we can use to manipulate lists. Shortly, we'll
look at the documentation for Python's dict API.

49
00:04:53,920 --> 00:04:59,938
You wouldn't normally find programmers referring
to these as APIs, but that's really what they are.

50
00:05:00,800 --> 00:05:06,080
If you create a system that other programmers will
find useful, you may decide to create an API for

51
00:05:06,080 --> 00:05:12,080
that system. For example, Google make all sorts
of data available. Raw data can be useful,

52
00:05:12,080 --> 00:05:17,600
but providing a way to interact with that data
is even better. Google provides a YouTube API

53
00:05:17,600 --> 00:05:22,960
that lets you query YouTube, to get statistics
on your YouTube channels. Those statistics are

54
00:05:22,960 --> 00:05:26,720
available when you log into the YouTube website,
but you may want to write your own programs

55
00:05:26,720 --> 00:05:33,728
to analyse the statistics. Their channels
API lets you do that from your Python code.

56
00:05:34,400 --> 00:05:38,960
Students sometimes ask how they can allow a
user to log in, with a password, before being

57
00:05:38,960 --> 00:05:45,440
granted access to a program. Our advice is - don't.
Authenticating users is extremely difficult to

58
00:05:45,440 --> 00:05:50,560
get right, and comes with all sorts of problems. You
may be aware of websites getting hacked, and all

59
00:05:50,560 --> 00:05:56,566
their customers passwords being stolen. If you need
to perform authentication, let someone else handle it.

60
00:05:56,566 --> 00:06:01,680
Google, Apple and Facebook, to name a few, spend
a lot of money on their authentication systems.

61
00:06:01,680 --> 00:06:08,425
They have the resources to make them secure, and
the money to spend on development and testing.

62
00:06:08,960 --> 00:06:13,440
Alright, so I'm going to switch over to a browser,
to show Google's documentation for their Oauth

63
00:06:13,440 --> 00:06:19,117
API that you can use from Python. You can see the
link on the screen - it's in the resources section.

64
00:06:19,600 --> 00:06:24,640
There are some setup steps you'd need to complete,
before using this API, but you can see here a

65
00:06:24,640 --> 00:06:32,320
description of how to use this Oauth 2.0 API
from Python. What's more, they also have APIs

66
00:06:32,320 --> 00:06:37,760
for Google Docs, Maps and a host of other things
that Google do. Unfortunately, they haven't produced

67
00:06:37,760 --> 00:06:42,480
an API for Google Keep. Programmers have been
requesting one for about seven years,

68
00:06:42,480 --> 00:06:49,626
and actually, in 2019 Google did hint that they'd
be providing one, but to date, we haven't seen one.

69
00:06:50,240 --> 00:06:55,840
An official API is supported by whoever created
it. More importantly, there's an implicit guarantee

70
00:06:55,840 --> 00:07:00,960
that the API won't be changed in a way that
breaks client code. If you write code that

71
00:07:00,960 --> 00:07:06,320
uses a Google API, for example, then Google will
make sure that any changes they make won't cause

72
00:07:06,320 --> 00:07:13,280
your code to break. The Google Keep API that we've
used is an unofficial one. A programmer named Kai

73
00:07:13,280 --> 00:07:16,960
created a module to use that API, and has made it available.

74
00:07:16,960 --> 00:07:23,931
But if Google change the way Keep works,
any code using Kai's API might break.

75
00:07:24,560 --> 00:07:28,560
Now if you're an experienced programmer,
you'll have no trouble finding Kai's API

76
00:07:28,560 --> 00:07:31,920
and working out how to use it. But
if you're new to programming, it's a

77
00:07:31,920 --> 00:07:36,160
bit early in the course to be experimenting
with your live Google or Microsoft accounts.

78
00:07:36,160 --> 00:07:40,800
By the end of the course, you'll be able to make
sense of published APIs, and use them in your

79
00:07:40,800 --> 00:07:47,440
programs. With a bit of extra code, our simple
meal planner program became a lot more useful.

80
00:07:47,440 --> 00:07:52,320
There's all sorts of APIs available, to
let us do all sorts of interesting things.

81
00:07:52,320 --> 00:07:57,040
Now if you think of something you'd like to do, google
for it - it's very likely that you'll find at least

82
00:07:57,040 --> 00:08:01,840
one Python module that will help. Alright, so
let's end the video here, and in the next one, 

83
00:08:01,840 --> 00:08:07,600
we'll have a look at the dict API - the documentation
for dictionaries. See you in the next video.

