The Brandwatch API is incredibly powerful and has many uses.
Just some potential use cases here:
Say you want to pull specific metrics into some report you’re doing. You could write a script and pull data directly from Brandwatch through the API and generate your report
Say you have 500 queries to write. You could have some “analyst” write your queries. Compile everything and with one click of a button you could upload those 500 queries all at once!
Using the Brandwatch API
Pretty simple, uses 5 basic commands,
GET pulls/request data
POST adds data
PUT edits existing data
PATCH edits parts of data, use it when PUT is too much
DELETE remove data
Using the Brandwatch API
OAuth2 is used by FB, TWTR, Google
Grants access to an application
Provides “access tokens” that can be shared between users
Data types
Brandwatch recommends JSON, because this is the native format for most browsers internal scripting engines
XML is a legacy format which most web applicaitons don’t use was the original format of the API1
Cue Nate to write login access
-if user successfully accesses app, will receive:
- access_token: aa000000-0aaa-0000-0a00-aa00a000a00a
- token_type: bearer
- expires_in: 31535999
- scope: “read trust write”
Access token values can be submitted with any other request to the Brandwatch API
“Expires in” lets you know how long (in seconds) the access token is valid for, default for an API user is one year
So basically when you make a request to the API (put, post, get, etc), you must provide the API with access tokens/must have the above information in the header
Today we’re going to write the login/authorization to Brandwatch API with python class objects to give an idea of structure (which uses params, login, url
So the parameters are as follows: username/pw, grant_type, client_id
Login stores access token when you get it
getUrl generates the URL request (formatting) for the brandwatch API
After the you make this request, the API spits out an access token, you pass the access token back into the URL when you make a request
Once we have this, we can write what the script actually does (here we’re retrieving project ids to use later)
Topics extraction by Nate
Querybackfiller/Query Uploader by Tian