All right, I'm going to. All right, I'm going to start again for part two of digital trace data and.
I hope you're all caffeinated and. Sugared up so fast before I start talking,
I want to make a plug for the I believe Taylor has put out a link on the slack on proposing topics for dinner discussions and not doing well.
We are not doing well because we have only one that's been proposed, although. Yeah, although although heads up first tonight,
Roberto is going to be leading a dinner discussion on the ethics and the challenges involved with web scraped data scraping web data.
And of course, did talk about his personal experiences with that.
But I know many, many of you mentioned, I recall from the lightning talks had been talking about using web scripted or had been or are using it.
And I think it would be a great opportunity for us to just have a discussion about
some of the challenges you might have faced or some of the bigger spending issues.
Yeah, because of Friday, Charlie will be giving the workshop on the issue with digital payment agreement or something like this.
Yeah, yeah. I don't know if Charlie is in the building, but I might write to my message and ask him to join this.
Charlie, if you're watching the livestream, come to dinner. Uh, hmm.
Anyway, so OK, so that's tonight, but I would really be great.
I mean, all of you are brimming with really exciting and interesting ideas or have just questions you want to discuss.
And maybe your question is, is computational social science even a thing and worth it?
And that's also a very good and the German question that we can have a discussion about.
And I think that the dinners are a great place to be able to do that for us, and we also will have some sort tonight.
You know, Roberto's already taken the slot, but we can also have two or three discussions going on at the same time if there is enough interest.
So. So, you know, just please fill in that sheet that dealers send out.
Yeah, there we go. The second is another. Yeah, there is that feedback from yesterday.
We got four responses.
They're not compulsory, but they're really helpful for us, especially if we want to do this again and to inform other six locations.
We've all learnt a lot from that one. And it's just open ended question.
So there'll be another one tonight about today, and you can also go back and answer about yesterday, things like that.
Just keep eye. Yeah, OK. So dinner discussions. And also, if you're interested in any particular topics, there's the proposed the topics on the right.
And so please feel free to start channels to discuss these kinds of.
Discuss things with just profit. And it's all state. Yeah, you just write a word or a little description of what you're interested in,
anybody who is interested in that can like it and then you have a sense you can start your own channel talking about.
Well, it's great to have. Yeah, exactly. OK, great.
So I want to start that now part two of digital trends data and the point or the
purpose of part two of digital trends data is so I've given you a kind of conceptual
overview talked a bit about how my how my social researchers use digital trace data
for answering social questions in terms of different kinds of research designs,
the strengths and weaknesses. And that was meant to sort of think very generally about this kind of data source.
And now I want to talk a little bit about kind of tools and techniques that we might use for working with with with web data.
Not necessarily here, just digital trace data, but web data.
We might adopt some techniques, such as web scraping or screen scraping.
I'll also talk a bit about APIs. Give the example of the Facebook marketing API since I talked a lot about research involving
the marketing API and then we have a group exercise that I hope that will start off today,
which will be first. We'll start off more individually. And then in that, I'll just ask you to work with an API individually,
your API of your choice or maybe the marketing API or something, the Twitter API.
And then tomorrow in the morning, we're going to dedicate the whole morning session to the group exercise just like we did today with FAQs.
OK, so the different techniques and tools. And this again,
is not meant to be an exhaustive lecture of every possible way that you might want to deal with web data
or all the APIs in the world because there are more than twenty thousand web APIs so I can go through.
I mean, it's like saying that there are so many services in the world.
I can teach you how to use every survey in the world, but I can tell you general principles of survey research, so think of it in the same way.
Right? So Web scraping is simply the process of automatically extracting data from Web pages.
Now this is perhaps familiar to many of you already because you've been doing some kind of web scraping
already and the slides that I'm going to be using now just rely on Chris's tutorial on screen scraping,
which is on the six main page, the Princeton page or the Princeton website.
So if you want to follow and actually try some of the code yourself, you could just go to the tutorial and follow along.
If you if you're interested.
Anyway, so as I said, web scraping is just or screen scraping is just identifying a web page that you can legally, as you see in the thing,
legally scrape and then downloading the source code, which of course, this is what a web page looks like to a computer.
It's the HTML at the back end,
or it could be an extra metal file and then essentially bypassing that source code to create a kind of data set that you can use.
And I think before we kind of go further, it's important to take a sort of pause and say,
is web is web scraping legal and there are there are there are.
I've come to learn that there are a number of opinions about this because there's website terms of service.
Are you allowed to do this? And often if you read website terms of service for a lot of websites,
especially large websites like Facebook or New York Times, they will actually say, No, you are not allowed to do this.
You're not allowed to automatically extract data from you are allowed to use it for individual use like, you know,
you're allowed to read these things, but you can't just kind of systematically have a spider of college is going around using these pages.
But I've also heard views about how terms of service are not legally binding agreements.
And as a result, there's not really a contract that needs to be obeyed.
I personally, as a researcher, like to err on the side of caution.
And I think and that's if people ask me,
I always say I are on the side of caution because you don't want to do something that might make things difficult for you,
especially if you know, if at some point it turns out that that that there is some contention about the usability of that particular data source.
So there's no, I would say, general pretty script here that I want to say other than say,
make sure you read and understand terms of services and also yourself.
Think about in the context of what you are doing. Is this something that that you know you do?
How does it fit in with your with your goals and your plans?
All websites these days also tend to have a robot start policy that specifies rules about automated data collection.
So, for example, this is Wikipedia as well robots policy.
I know Pablo here is an expert on Wikipedia, so you probably have seen this this policy?
Have you? Have you read it? No, there. Well, you don't have to read the policy.
But because Wikipedia is OK with it, most, most crawlers, you know, there are no kind of an open, open source, open encyclopaedia.
But of course, there are some web crawlers that they don't like because it's observed spanning large amounts of and ignoring rate limits,
and it's disrespectful and so on. So as a result, you know these some of these are disallowed.
So even on Wikipedia, there are some bots or there are some crawlers that are disallowed.
So anyway, so most websites these days have these kinds of robots.
So you should if you are planning to do use some kind of a crawler, you might want to crawler by crawler.
I mean, just essentially some kind of a computer programme that is crawling or going
through many different kinds of web pages and extracting information from them,
usually quite regularly. And usually crawlers tend to work with the they might have different kinds of rules.
But you know, one column I go to one page and then go to all pages and links to that page and then so on and so forth,
so it can quickly become a problem that is is is quite large.
Well, thanks for Los Angeles. I know I'm referring to the callers as the programme, the computer programme.
Right, so, yeah, a crawler in this case here would be just, yeah, the computer that is going around collecting,
but obviously it's I assume it's usually it's designed by an individual or team or something.
So yeah. So these, for example, these crawlers here,
most of the things that they don't like on Wikipedia tend to be advertising or our media partners, Google and so on and so forth.
Anyway, so this is a straight forward Wikipedia page. There's just the World Health Organisation's ranking of health systems.
And on this page, this is what the back end looks like.
There's the HTML of this Wikipedia page.
And really, if Wikipedia is actually if there's like, sometimes good information on Wikipedia, you might want some tables from Wikipedia.
And as far as scraping Wikipedia goes, it's a fairly manageable.
It's quite it's quite an easy, easier resource to describe.
It has generally the same structure and and and and the AH best package from ENR have.
Have any of you used our best? Obviously. It's actually.
Being 31 now, it's not being used.
Yeah, it's switched to examine what to do.
There's just pretty much anything that you do our best.
OK, so horror is suggesting that better than our rest is eczema.
I mean, it's not. It does, but it does the same kind of things. Yeah.
I mean, I've seen like the Office Suites, so it's not, yeah, much too much maintenance.
No, I mean, you can still use our best was that was was one of the most widely and is one of the most widely used.
Still, I think, for doing simple static web pages and it you just would.
You would read the HTML page in the hour window.
You know, I would tell you it's an next document. This is what the output looks like for.
If you if you just read the HTML is what it looks like. So that object and then so you would then go to.
So this is back to that web page. So this is open in Google Chrome.
You would go to your developer tools here and then in order to be able to scrape this web page.
So I assume that I want this kind of table on this web page. There's the table on the table, on the rankings.
So let's say that this is the this is the information that I want, right, I want this table is what I'm trying to extract information on.
So I would just go and I would go and identify on through the developer tools.
I would go and inspect and find the ex-boss for this. So I would just go and copy the Xbox where this table starts.
And then it's quite straightforward. I would just go use this HDMI underscore node command and then I would specify the Xbox.
And as a result, I would be able to and then using this HDMI underscore table essentially be able to extract that table.
So this is a pretty easy web page to scrape with essentially three commands.
Using this harvest package, we can import and pretty nicely analyse this this table.
Of course, most web pages are not Wikipedia, and they are not as straightforward to extract tables from.
In my experience, often sites that have a lot of tables where you might want information, even if they don't have,
they might not be, as there might be quite interactive and very difficult to extract information from.
But often they'll have on some part of their webpage that might have a JSON file.
And these JSON files, which is often, you know, which is just as I said,
which I've come to as well later is just a data storage format with lots and lots of curly brackets.
And it's often the way in which a lot of information is stored, especially on the web, and can be used to do to you.
Using the JSON format, we might be able to collect a lot of this information that might be available on these websites somewhere.
But at the same time, the tables directly might not be able to be scraped.
So, for example, for a project, what I was interested in using the Global Gender Gap Report.
The website is very interactive, was not easy to scrape, but actually did hidden on their website.
I just found all the tables and JSON, so it was much easier to use them that way.
So it might be useful to see if on some kinds of data sources that you are interested in, whether there is that that JSON file somewhere on the.
Anyway, so for more complex features, as I said, this kind of static, the simple code doesn't work.
And then especially those would have like a lot of these stylesheet, a cascade instantiated CSS elements.
So we might need other approaches so we might use something called the the selector gadget, which is this plugin you can put into Chrome,
which then allows you to sort of point and click and find the parts of the page that you want to describe.
So, for example, here this is the part defined in the example.
If I were interested in just getting this far,
I would just kind of point and click on the different CSS elements and then the selector gadget would kind of identify this for me.
And similarly to what we were doing before using again, the HTML loads instead of Xbox.
Now we'd specify the CSC, and then that would then be used to extract this information.
We still would probably need to clean this, data said, because, you know, we would get some information,
but the strings might be messy or they might not be in the perfect format.
So there would still be processes in which we would need to do some data wrangling.
But at the same time, that could be an alternative approach to also do some kind of web scraping if we wanted to.
Anyway, in practise, this is Web scraping and can be messy, it can be difficult, and it can yield data that aren't always as straightforward to use.
But again, this is problem specific. There might be, in some cases that might be the only thing you can do.
You have to just clean, messy data, and that's what you have to do.
But sometimes you have an alternative, right?
And maybe Roberto might talk about this also in the structured in the sort of in the dinner discussion that we have.
One approach, if you have a complex web page and you're interested in extracting information from it,
you might want to outsource this to crowd workers.
And so you might want to use Amazon Mechanical Turk as a way to send people to different links and say,
Extract this information for from this web page for me, and I might put it on.
So you might want to outsource it to on a cloud worker platform as a way to
collect information from a web page rather than trying to automate the process.
Another approach, of course, could be that you could use a web based API if an API were available,
because some websites do make their content available in application programming interfaces just by show of hands.
How many people here have ever used or interacted with an API? OK, so the vast majority of you have some experience using APIs already.
Can I get I get a sense of what kinds of APIs you've used.
At the back, maybe closer to either directly or through an hour package or something akin to a Python packages.
The translation, which Facebook API follows on the graph.
Yeah. I use one for males.
It's of the genealogy that you get like the genealogy of some names, you find out people's age, gender or race based on their.
Yeah. And that one was a very large sample. And you get the URL.
Yeah, whatever content inside.
Yeah, yeah. Oh yeah. So we have the scale of what I knew.
I'm interested also, by the way, just because I think this is also an opportunity for you to know what other people have done.
Also helpful from the perspective of your projects. Yeah, it's one that we still.
Uh huh. She.
Excellent. OK, so we have we have social media APIs, we have air quality, we have genealogies now.
Actually, the API, it's so the bicycle life bicycle.
Uh-Huh. That's another. Then this thing.
Yeah, yeah, yeah. They have a live Yuvi every second.
When you change or move a bite. Oh wow, actually recorded in, you can see.
Yeah. Oh, that's very interesting. That's cool. Yeah, I actually built this sort of like an automatic box to grab every day or record data.
Yeah. And then they have this message for all public data in Spain for all different open, open data.
Yeah, OK. So we have sort of transport and also a public API.
Any other experiences? Yeah. Google perspective on.
Are. So what can you tell us a bit more about what it does?
It's. Uh huh.
Species that they've developed, and I think most. Moderation.
Lots of users to. Some politicians.
And they have been developing algorithms to classify speech.
Ways these countries kind of one and also. Also, some.
Is to. Yeah, yeah, so so it's it's a data analysis API.
Yeah, so that's also an interesting aspect here because so far we've had a lot of APIs that are just you're retrieving information from them,
but in your case is also doing some some additional analysis. Right.
So it's it's analysing info so so you can have APIs that are both, of course, storing and you can collect information, right?
You can pull if you can pull information from an API,
but you can also basically make a request to an API to analyse something something for you, which I think is also an interesting dimension here.
By the way, I would also suggest for those of you who have talked about the API that you're using,
if you don't mind, could you put links on the slack so that other people also have a sense of what these APIs are?
Yeah, what also is called the open corpus API open corpus allows you to query any name of the firm.
Yeah. Mm-Hmm.
What the government was imagining, so probably a lot of problems that Apple would have liked and brothers and sons would have mentioned,
it goes away and now allows you to get a fuzzy mention on that for the next time.
But the data and you need to know any mentioned and which starts from nowhere from.
Now. OK. So that's and that's global arts. Oh, wow.
Also, you do YouTube API. Sure, opponents, the retailers even preserved Venus with subtitles or captions.
Yeah. All I can say for. Sure, sure.
And have you use that in your own work? Yes.
Here you are using such intense mediations, but again, we're also going to reach this embroiled in this discussion.
And most of them are writing. Yes. But this is not original there, I think so.
Yeah, sure. Results showed that most of the journalists wishes images are related in some way.
That's right. Right. So so this is an example of this.
The YouTube API is as actually still quite rich, right, in terms of providing you a lot of information.
And and it has as far as I haven't used it myself. But what is the credentialing process like?
Is it? Is it fairly straightforward? Can you do it with anyone with a YouTube account?
Can or do you need? Yeah, yeah. Yeah. And anyone else have any other interesting examples from their own work or, oh,
Google Translate API, Google Translate could very easily fetch that, right?
Yeah. Yeah. Me, yeah, we have some live stream ensure that.
Yes. Yes. OK, yes, thank you. Anyway, it's hard to it's hard to be spontaneous and have a discussion while at the same time be anyway.
So. So like the reason I asked all of you in addition to this,
being a community sharing exercise is to also illustrate that web APIs exist for purposes of data extraction and data analysis, right?
So he has a translate, and this was the Perspective Perspectives API.
The other thing that's cool about them is that they exist for all sorts of domains, right?
So we have social media APIs, we have APIs that are providing air quality data that we have genealogies.
So we have really a range of.
And they're also providing all sorts of of when you do kind of get requests to them and you ask them to do to get some information,
you can get information and all sorts of forms. Often you get some kind of adjacent area, which will be, as I said,
this format where things will be will be text and lots of curly brackets with lots of these.
These quotation marks are. But at the same time, sometimes as you can also get different kinds of formats.
But what is an API for those who haven't used APIs is an API is simply a software intermediary that allows two applications to talk to each other.
That is very generally an API is just allowing for two applications two to talk to each other and they get an example for.
This would be if you think if you think about, for example, so on a web API.
More specifically, it allows a client or a computer to ask another computer, usually a server, for some kind of resource over the internet.
So if you think about, for example, these aggregator websites that like Momondo or Expedia or Kayak Ride,
they themselves don't actually have the availability of flights on the particular
date and all this information on their own systems on their own servers.
But at the same time, they still access that information and show it to you when you make a query to them.
So how are those two websites interacting through an API?
So there's a structured bit of exchange going on between, for example, Momondo and British Airways when you make that query.
And that's usually happening through some kind of an API,
and that kind of exchange is then then what you see there and what are your final product is that's been enabled through that API?
What's cool about a lot of modern APIs is that they are they adhere to standards
that make data exchange between them programmatically quite extensible,
structured and generally safe.
And another thing that I think are kind of interesting and cool about APIs is that they generally require some kind of credentialing process, right?
So they have some kind of key that you need or some kind of authentication process that you have to go through,
which in some sense gives them more legitimacy than you would have where you would just sort of crawling or scraping a web page.
So sometimes people like to draw a distinction between, you know,
an API based data strategy versus a versus one where you've just kind of scraped something off the web.
You have a point, where do I? Well, it's good to exercise the OK.
So that was my brain about how this the API and really starting around the 2000s
when there was this whole development of standards and an explosion in web APIs,
really, there was really an expansion in the in the number of APIs that are available.
And this is a good resource programmable web dot com slash APIs where you get a
sense of all existing web APIs that are available for all sorts of purposes.
And this has, according to Chris, this has about 20 thousand and counting, and it tells you about all categories of of of APIs.
And you see a lot of them are from the mid 2000s, which is when this kind of boom in APIs occurred.
And now I would think we're sort of reaching a plateau where there isn't really kind of a hex expansion really, that's happening at the same rate.
And maybe we don't know, but maybe there might even be, as I was saying earlier,
post API age where where there might be more challenges to data access.
So most Web APIs tend to use hypertext transfer protocol or HDB methods, you know, which you are familiar with,
because when you are making any query, when you type in a URL, that's going to be GDP, that's how it starts with.
And it should be is the network protocol that delivers virtually sort of all files over the internet or over the world wide web.
So HTML files, image queries, everything. And the nice thing about HDB methods is that there are these kind of four or three that get
forced delete and a few other verbs that are used to do to interact and make requests with them.
So I think two of the most commonly used ones are get togethers used when you are requesting a page and post
is usually when you're like submitting something to a server or when you are submitting a form to a server,
that's a kind of a post post request. And the HDR package and hour is a great way in my experience to just work.
It's very useful to work with all kinds of APIs, and you can make a request to a URL, get a response.
And the word for that is get g d. And the response usually contains the kind of all responses will have a status, a header and a body.
So here, for example, I made a simple request. So there's HDR.
I just said that I'll show you in the next slide what this is.
But I said I made a request to this this 8TB dat API.
And and then and then I just say I queried and I said, What is it?
Is it is called and I said, trial and this is two hundred.
And for those of you who have used HDTV, two hundred means that this was a successful request.
So two hundred is a status code for success and 400 is like bad right for 100 is no.
Somehow something went wrong. You didn't get access or 400 error, usually unauthorised or some problem, some credential.
Something's wrong. So and then and then I just said, Well, what is the content of this?
And I get these kind of numbers because this is what this is, right?
I made a query to the cat. And what's cool about this is that so this is a joke, right?
They have all the error codes with cat photos. It's the cat API which has the I don't know anyone else seen this before now, OK?
They also have a dog API yesterday.
So yesterday, when I was having dinner, my partner said, Why did you have a dog picture instead that dogs are cuter than cats?
And I was like, No, I know that Cat API anyway.
So the the nice thing about this is really what you see is that my point here to show you the cat API is is first.
That was a very simple command, but you're making a request to different kinds of data in different formats.
So this is not a JSON object, but you got a cat.
And that cat is an image anyway. So. There's the Facebook marketing API, which is an example again of a social media API that I use some example,
some papers and I describe some papers that had used this.
And that's an example, again of a social media API that we might want to use and could interact with using the R package in our.
And in order to do it, the credentialing involved is you need to have a Facebook account.
You need to have the marketing app with token and ad account number or act.
So rather than opening my my Facebook account here and showing you how to get these things,
which would involve me also showing you my own credentials, I suggest if you want to get these credentials.
Sophia Gill Flavell from the Max Planck Institute for Demographic Research has very
nicely and helpfully prepared a tutorial on how you can get these credentials.
So I don't have to reveal my Facebook timeline and history is here,
so I suggest you go here and link if you're interested in getting these credentials to to set this up.
But if your goal essentially if you open your Facebook account and this is perhaps
a legitimate reason to open your Facebook account at this point in the lecture,
if you want to, you know, if you go up to the top, where on the right on the right hand side,
if you click the little arrow or a dropdown menu where it says marketing on or marketing platform, I don't know what it says,
but if any of you have a Facebook account that you want to open and you want to see on the right hand side,
there's a part where you can see advertising on Facebook is what it says.
And if you go to advertising, if you click on that link advertising on Facebook.
This is the Blacks. This is generally what you get in the end. You, you make a few more next next steps and then this is what you get at the at.
From that on the front end is what you see and what this tells you, as you can create a new audience here, right?
And you can say so yesterday night I created an audience and I so at the moment,
there's this cricket World Cup going on, and I'm very excited about it.
But I didn't watch it yesterday. I was very sad.
And then I was thinking, Oh, I wonder if other people in Oxford are interested about the Cricket World Cup?
And then I did a search request. I did a query request yesterday to see, Oh,
what is the size of the audience that might be interested in in cricket and the Cricket World Cup on Facebook?
How many Facebook users are interested in cricket and the Cricket World Cup in Oxford and all?
So I just said men, women, all between the ages 18+.
And it turns out, according to Facebook, thirty eight thousand people are interested in cricket and Facebook, which I was kind of surprised by.
I thought it would be a lower number. So, yeah, it was. This is an example of basically making a targeted audience on.
On on Facebook now this is telling you how many users meet certain characteristics by geography,
by age, gender and then actually a range of different other kinds of detailed targeting.
This was just a very sort of casual request, just looking at interests.
But you could also do this by things like parental status.
So in the tutorial that I've prepared to accompany this lecture, which I think is also on the website for six Oxford,
you'll see an R&D file where I link to some pages that have used this data source for research.
And you can see that this that the view is different behaviours or interest categories to create measures and variables with this.
So this is on the front end. This is what it looks like, right? This is what the the the numbers look like.
But actually, programmatically, we can make a query to this API to retrieve what are these?
These add audience estimates. These add audience estimates are just the measures of how many Facebook users match certain characteristics.
And you can do pretty detailed estimates or you can do very aggregate estimates.
So but but it's possible to obtain these programmatically using the the marketing API.
And what are these are essentially targeting specifications.
You can specify what categories you want to target and get sell sizes or columns for and this website.
It's actually quite a well detailed in terms of the information.
It's very well documented and it tells you how different things are are operationalised.
The one drawback, though, in my experience with working with this API,
is that it changes all the time and you go through many versions very quickly so that if you have previous base,
you URL that you used as a syntax,
things change and then the query structure changes and then you have to essentially be mindful of that or targeting specific actions get moved around.
So what used to be classified as an interest before becomes a behaviour? And so then you're so old code might not work.
If you are done a query, say, you know, with an older version, it might not work with the newer version.
Yeah. How do you deal with this in your gender project, which essentially does this every day?
Yeah. So the one way we deal with this is there's a person who works on the project and and and when he notices, something is wrong, he he.
But that's a really good point, and it's a really good question.
And that's one of the reasons we actually hired someone for this was because it became that if you want to do this on a long,
if you want actually want to do this kind of connexion or you want to have a platform on your dashboard but is actually doing this,
have regularly, you need to be, you know,
we need you need to have someone who is dedicated to actually monitoring these kinds of changes because otherwise it would not be.
And even then, even when you have someone working on this, you know,
sometimes you don't realise that the changes occurred and then you notice two days later that the data was collected and why were they not collected?
So yeah, it's it's a bigger and. And actually, this has been an issue.
I don't know if others have had this issue that sometimes, you know, things change and you don't know what changes.
And so, yeah, go ahead. Do you have to find a deposit before spending any money on Facebook?
Yeah, good question. Yeah. So just to actually launch the ads, you don't need to do launch to actually run an ad,
you need money, but in order to query just accounts you don't need, it doesn't cost money.
So you. So if you were to run an ad,
if I said if I actually went and ran an ad for these thirty eight thousand people in Oxford who are interested in cricket,
then yes, I would be paying. But I just asked for the account, and that's free.
Well, all APIs have great limits and and this is a concept where if you query too much, too fast,
then you are basically you're being disrespectful and you know your your access might be compromised as a result of that.
But as long as yeah, so what rate limiting means, essentially is that if you wanted to extract a lot of queries, it would take a lot of time.
But limiting also means that, you know, if you do stick within the the rules of the game, it's fine.
There are also different levels of tiers that we found, so we were able to improve our status for digital gender gaps to go from a.
I don't know what to steer officially, it's called, but we went to a higher trade to our highest atmosphere,
which allowed us to have a shorter gap between queries.
And the reason we were able to do that was because we went through again an additional authentication
process where we explained why we were collecting these data by making a little video about it.
So that was an additional step to reduce the time between queries to five seconds or I think of you instead of eight or nine seconds.
So that's so that's kind of a strategy that some might allow you to have.
So these these links are very helpful in telling you about the API keeps changing.
And this is a problem that we've encountered. So at this point for version three point three, which is the version of the API so far at the moment,
sorry, this is kind of the general structure of the URL.
It's graphed out facebook.com slash the version of the API Act and this would be your ad account number.
The delivery estimate and the delivery estimate is basically telling you that it's one delivery.
Do you want what kind of customer do you want anyway?
And then you have to first authenticate yourself with a token and that that's the token that I was telling you.
If you go to the tutorial, that service that Sofia is prepared, you'll be able to see it how to get those tokens for yourself.
But again, we already discussed this. It's important to remember rate limiting when working with the APIs I worked towards, I think.
Is the tutorial online? Yeah, yeah.
So I just go to that. But before I just I go to the tutorial next on the on the HTML file, but I just wanted to say that as a general principle,
this kind of targeted advertising counts for how many users on a platform meet certain characteristics.
This kind of online advertising data as a general principle is not just limited to Facebook.
It also exists for Google. It also exists for Twitter, for instance. So, so this is an example of Google AdWords here.
This is AdWords trying to start an advertising campaign.
So these are going to add data available for advertisers. This is what I'm trying to start a new advertising campaign.
And I'm saying create a campaign and I've chosen gender, age, parental status, household income.
This is only available for like the US household income as a targeting criteria or like us and a few other countries anyway.
So what you notice here is orderly. So I chose everything. And then you notice here that it says your targeting reaches 10 billion.
Now I'm a demographer. I know that there are 10 billion people in the world.
So why is Google claiming there to be 10 billion people? So what is the problem here?
So it turns out that unlike Facebook, which gives you estimates of users,
what AdWords is giving you is estimates of impressions and impressions is vaguely defined in the impressions as defined in their in their strategy,
in their documents as just how many times an ad would be seen by someone.
Right. So how many eyes would it encounter? And actually, in the context of our gender gaps work?
This is interesting because I haven't included a figure here about this.
But when when we look at the same ratio of the Facebook gender gap,
we find that the gender gap or gender inequality as estimated by a ratio of Facebook users,
if we had a measure of digital inequality as measured by the ratio of female to male Facebook users,
is actually much more optimistic about gender equality than the Google AdWords based measure,
which suggests that there is a greater gap between men and women.
And part of the story there could just be that, you know, if men have more time on their hands for leisure activities,
they might be spending it online or they might be surfing much more online relative to women who might be using.
They might have internet access, they might be using it, but they might not be using it as much.
And as a result, the impressions they create are not as many. So.
So even though the two measures of the Facebook gender gap in the ad were gender, gap has a very high correlation generally for the same country,
the Facebook measure tends to be much more much higher than it is for the Google AdWords gender gap.
That's what we've been finding in our in our work here and in general.
We find that for the kind of the women we're trying to estimate internet use gender gaps and invalidating against survey data,
we find that Facebook does better on its own than AdWords.
But the best models are those that combine Facebook and Google try and do when we're trying to make a prediction about internet use gender gaps.
Anyway, so what I want to do now is just run through quickly the the tutorial on how to use the.
The API from within our. With this, whether this is a digital jam, the gas website, as you can see the reports for the different days.
And then see different days, how it's evolved. You can also see how we tried to estimate the mobile phone in the Gulf and so on.
But you know, where is it? You know, I heard. OK.
How can I go back down with this? We'll take this year.
OK, so. So what I've done in this tutorial is just give you an example of how to get estimates from the API,
from the marketing API using your our console and you don't really actually need that many packages forward.
You just need HDR and JSON light because the query is returned in JSON format and then and you will put in your token in your act.
And as I said, this sort of the general structure of the URL that you're making a call to is quite straightforward.
Graph Facebook.com, the version, your credentials and then the key information is going to be this targeting spec, right?
So the simplest targeting spec here, so the targeting spec is specified as a JSON array,
so you have to specify it in these kind of curly brackets, but I'm dealing with it as a string here and here.
Although if you had a more complex array,
you might not want to deal with it as a string and you might want to work with it as a separate JSON object and then import that into our.
The Keystone. Is no good question.
So, Jack, almost question is, can you get historical queries? Can you go back in time and see how many users there were in the past?
And actually, that's a big limitation, say, unlike Twitter, where at least you could theoretically go back at least a few days in the past and the
free access that you get to the Twitter API and even longer if you had paid access.
Although I don't know, the standard rest API let you go backward seven days or how many.
Yeah. Seven days or something, but you can you can get premium access and go back.
And there are some places that have access to ladder. The fire hose, I guess who have access to all this is a big limitation of this data source.
That's actually one of the reasons why in digital gender gaps,
we're collecting it prospectively because we're interested in looking at change over time.
You're not going to pay for access. Which makes you think even for years, it was only a matter of years.
And there's also a certain university. But yeah.
Now, so the sometimes called the Twitter. Does anyone I mean any of your active Twitter user, I mean active Twitter users for research.
I mean, because the standard rest API let you go back a few days,
but with some universities you have access to what's called the Twitter firehose, which is a very large sample of, I think, tweets ever.
All tweets, ever. Yeah. And there might be a few other universities that have access to that.
And that means that. And again, this is coming back to the point I was making in the first part where one of the reasons why we've
seen so much digital trace data research use Twitter is because Twitter has been actually very open,
unlike other platforms that have been much less open. So I think so.
Twitter has posted this this Facebook.
Not this this information. No, no.
But that's actually one of the reasons why we're going forward in time is to try and get around some of those.
Of course, Facebook, I'm sure, has it, but it's a different issue.
But yeah, so this is a very simple query, what I've just said, all people in GB and so in the UK and I've just said.
And if you don't specify any other targeting specific nations, then you will essentially the others will be left stunned by their default.
So in the documentation, it'll tell you what the defaults are for all of the other specifications.
And then I've just created a list here where I've said, these are just some attributes that I want to specify in my query to the API.
But I'm saying that I want to get a reach estimate. That's kind of my optimisation goal.
I want to just see what's the reach of my ad,
which is the equivalent of like how many people would see this ad or what would be the audience size of this ad?
There's a I've also said, for instance, that this is method get,
which is that's the get verb from the HTP protocol that I'm just extracting or I'm requesting this estimate.
I don't want to make any changes to anything, so it's just getting it.
And I'm saying this is a targeting specification and that's my targeting specific vision.
I just want to know how many people are, how many are Facebook users in the UK?
And that's what. And then I make that request using the R package and then I just and then I say, Tell me and I just pass this content as text.
And I because it's as I said, the output is Jason. And then this is what I get from it.
I get a list and then one one element in this list is this is this data data frame and you can see that it gives you these kind of four columns.
It gives you estimate, double estimate mall, an estimate ready estimate dole refers to daily active users.
The estimate now is the monthly active users, and estimate ready just means that this was a successful request.
So, for example, if you were doing some error handling which you might want to do if you are making a range of requests,
you might want to check if this estimate already is equal to draw or not.
If you wanted to just confirm that you were actually getting a plausible request.
This is another issue we encounter a lot as we get a lot of implausible requests, we get a lot of.
So, for example, we get a lot of thousands and we know that, for example, the population of the US doesn't have a thousand Facebook users,
and thousand is generally the smallest cell count that they're willing to reveal information for for the monthly active users.
But at the same time, a thousand can also just be sometimes thrown up as doesn't happen that much.
But sometimes it happens that we get unexplained thousands, even though in the same country the previous day, it was not a thousand.
So it seems to be some kind of an error. And I've talked with others about it and they feel that this happens, but it doesn't happen that much.
But it happens enough that you should have. If you're doing a lot of queries, you should probably think about that.
Another thing you might want to do is, of course, is again, to go back to HDB status codes, you might want to check if it should be code equal to 100.
So was this a legitimate? And was this a successful request or not?
When you if you were just trying to collect a lot of queries and wanted to
make sure that you had successful requests because so this was just as I said,
it gives you the Dow, the model you might want to make a more complex, quick, sorry complex query.
So here I put a I said age, I would age minimum max.
So I said here I said, I want to query which is a GBE in Spain, so U.K. and Spain.
And I only women in GB and Spain between the ages of 20 and fifty five.
So that was my query this time. And I also said those who location type is home.
So Francesco was mentioning this yesterday. They allow you to specify whether you are.
You say you live in this place and you're actually living or alternately, you might be commuting from somewhere else.
So there are basically different location types that you can also specify.
So these are people who are essentially say that they're living in Oxford and they're also being seen as is a group based in Oxford.
So this is kind of a this home measure, then the device platforms mobile and desktop.
So I put in some more specifications. But the query structures exactly the same, just the the JSON array becomes a little bit longer.
And then I see that I get forty two million users and maybe I don't know if this is updated or did Dominion.
I guess it's only women, so it's fine. I was like, This seems kind of small.
Forty two million for women, twenty to fifty five GB and Spain.
Another thing to note here is that by default, targeting specific actions as an end query.
So it will not tell you GB or Spain or Italy and Spain.
So if you wanted to get to know GB and yes, separately, you would have to make two separate requests.
And as a result, that's what I was saying, that if you wanted to make a series of requests about different countries,
you would just have to do this in a loop and make sure that in your loop, you would put in to avoid getting rid limited.
Maybe this time, you know, a certain number of maybe eight seconds if you are in the first year of this.
So this is a. So another aspect of this API, which is quite useful when you're working with it, is that you have.
So this is the actual get so. So this is actually when you want to extract the estimates.
If you actually wanted to see what are the targeting criteria that are available, you could use this the search API of the marketing API.
And this what I've done here is I've looked at I've just said so using slightly different URL, but I've just done search here.
I've said that to me,
the art that the ad targeting categories of behaviours and this is my token and then tell me what's available in these behaviours.
And you see. So this is just the list of the first 10 behaviours of the 300 that come in this table.
So you can see that you can target by frequent travellers of technology early adopters.
Interesting Facebook Access OS, Mac OS, Windows XP anyway.
So device types these kinds of bits of information anyway.
So this is just sort of a way that you can start if you wanted to extract some data from it.
But again, there are many different APIs for many different kinds of things.
This is just an example of one that I've used and that's been used, for example, in.
This is the that is being used for this digital gender gaps work, right?
This is the data source that we're using. And so it will come back.
So in there for the next maybe half an hour before we go for dinner,
I thought maybe we could just work on if this would be our exercise for the afternoon would be familiarise yourself and obtain credentials
to work with with maybe one of the either the Facebook marketing API that I just talked about or potentially the the Twitter API,
which for which you can interact directly through an R package. And Chris has a very helpful tutorial on how to use the R tweet package,
which is linked which is linked here on the slides, but is also actually I can test if it's linked on the slides.
I smoke, it is linked on the slides, but or you can also just use it in some some other way.
I should note that Pablo Barbaro, who's going to give a talk here on Monday,
has also said that [INAUDIBLE] talk a bit about his own our packages because he's developed similar packages to use Twitter in an hour,
and [INAUDIBLE] give a demo of some of his package it packages on Monday as well.
This is a different package than his package. This one is, I think, by my journey.
It's also a good package or another API of your choosing.
So just for the next half an hour, if you wanted to work on just familiarising yourself,
get credentials and then maybe do some, especially for those of you who have never worked with an API before.
Just just get familiar with working with one for the next half an hour because I plan for tomorrow is I don't know, should we break for that?
Should we make the groups now or the.
We did in the morning. Yeah, but then but then I revealed the strategy for other groups are made.
Oh yeah. Well, OK. Anyway, so this is going to be the group exercise that we're going to work on in the morning.
Divide yourselves into groups of groups by counting into four, which is why because they didn't know about this.
So it's kind of bizarre genus. Then the yeah, now they might strategize on those anyway.
So I want you to divide us having two groups or groups of four and then work together to identify a research
question that you believe could be answered using one of these three sources of digital trade status or not.
I mean, there are many different sources, but I just want you to think about anything that could be done with one of these three.
And and think about it in the context of what question you would ask.
But also think about research design, given that, you know, some of them have some stuff and some limitations,
and then try and collect some preliminary data to test the feasibility of being able to answer your question.
And think about how it could potentially be improved by some kind of hybrid design.
So this is what we're going to work on tomorrow.
Let's just let's just sort out the groups at this stage so that there's no strategizing about this later.
Yeah, and then we can also discuss the topic more at dinner. So, Jack, what do you want to start off by saying one of to things or no one?
This morning was the other day as part of this. How many are we willing to sacrifice?
We want to have those people. I mean, what was our total number?
I mean, I don't know what is there going to be one two three four five six seven eight nine 10 11.
I'm very confused about who I'm counting gold, I will go with five.
OK, that's fine. OK, fine.
Very. For. OK, so then those who can be here after the auditors are not counted by.
I'm sure for one.
Two, three, four five. And then and then we have some who haven't counted, you counted one two.
You can't make it OK. Do so we have we have a shortage.
Then we have one group that there's only two. And the rest that have.
Yeah. Are they not?
I would be talking about. OK,
but or we can just have then we just have some groups that are fighting and just
some that are poor because we don't we can't even spread because there seems to be.
Yeah. OK, so group number two, arbitrary group number two, could one of you could this could the second person who was group number,
do you say one that's you will and will be in the group with the the two who are unclaimed?
I can see people that are on the same boats.
Yeah, but it's part of the other side, people on both sides, so they are fine, they're fine, then OK, then we're OK.
So those are some groups that are far right. That's that's fine, then.
OK, my problem is more is less complicated than I thought. OK, good.
Perfect. So that's what we're going to work on tomorrow. This is going to be the question you might want to interact with your group.
And so there we have Group Group one, Group two, Group three, Group four and five.
There's going to be the agenda for tomorrow, but for the agenda until we break one until about 5:15 or maybe 5:30.
Is this? Yeah.
It's on the website and on this line, you know, this markdown thing is on the line.
This one, it's on the website, it's called tutorial.
Yeah. You remind me, I need to ask before you.
The one ActionScript. It's not working, I think.
OK, I'll show you where it is, though. It just click on it.
No, no, this is for the art weed so well that you were.
Just go to the just go to the summer institute. What are the Princeton's page?
And this and this is the link for. So it's this one.
Oh, I just. So this is the Twitter. So this is using our tweets otherwise.
Otherwise, if you if you prefer using Tableau Barbara's packages, that can show you his.
He is. Did you see it or this is what's new?
It's called it's called application programming interfaces in our.
But they didn't do it, it's just that I can put it on this lack, maybe I'll do that on the sly.