You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add a seperate option for premium accounts to use consumer_key and secret values and inherently generate the bearer token on startup
* b64 encode expects a byte string
* after some more testing, better understood the required headers
* updated docsstrings around credentials allowing consumer key/secrets
* updated docs for credentials
* simplifying bearer token retrieval
* updated base readme with new docs
* update version
Copy file name to clipboardExpand all lines: examples/credential_handling.ipynb
+29-14Lines changed: 29 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,17 @@
6
6
"source": [
7
7
"# Credential Handling\n",
8
8
"\n",
9
-
"The premium and enterprise Search APIs use different authentication methods and we attempt to provide a seamless way to handle authentication for all customers. \n",
9
+
"The premium and enterprise Search APIs use different authentication methods and we attempt to provide a seamless way to handle authentication for all customers. We know credentials can be tricking or annoying - please read this in its entirety.\n",
10
+
"\n",
10
11
"\n",
11
12
"Premium clients will require the `bearer_token` and `endpoint` fields; Enterprise clients require `username`, `password`, and `endpoint`.\n",
12
13
"If you do not specify the `account_type`, we attempt to discern the account type and declare a warning about this behavior.\n",
13
14
"\n",
14
-
"For premium search products, we are using app-only authentication and the bearer tokens are not delivered with an expiration time. They can be invalidated. Please see [here](https://developer.twitter.com/en/docs/basics/authentication/overview/application-only) for an overview of the premium authentication method.\n",
15
+
"For premium search products, we are using app-only authentication and the bearer tokens are not delivered with an expiration time. You can provide either:\n",
16
+
"- your application key and secret (the library will handle bearer-token authentication)\n",
17
+
"- a bearer token that you get yourself\n",
18
+
"\n",
19
+
"Many developers might find providing your application key and secret more straightforward and letting this library manage your bearer token generation for you. Please see [here](https://developer.twitter.com/en/docs/basics/authentication/overview/application-only) for an overview of the premium authentication method.\n",
15
20
"\n",
16
21
"We support both YAML-file based methods and environment variables for storing credentials, and provide flexible handling with sensible defaults.\n",
17
22
"\n",
@@ -25,7 +30,8 @@
25
30
"search_tweets_api:\n",
26
31
" account_type: premium\n",
27
32
" endpoint: <FULL_URL_OF_ENDPOINT>\n",
28
-
" bearer_token: <TOKEN>\n",
33
+
" consumer_key: <CONSUMER_KEY>\n",
34
+
" consumer_secret: <CONSUMER_SECRET>\n",
29
35
"```\n",
30
36
"\n",
31
37
"For enterprise customers, the simplest credential file should look like this:\n",
@@ -37,14 +43,18 @@
37
43
" endpoint: <FULL_URL_OF_ENDPOINT>\n",
38
44
" username: <USERNAME>\n",
39
45
" password: <PW>\n",
40
-
"```\n",
41
-
"\n",
46
+
"```"
47
+
]
48
+
},
49
+
{
50
+
"cell_type": "markdown",
51
+
"metadata": {},
52
+
"source": [
42
53
"By default, this library expects this file at `\"~/.twitter_keys.yaml\"`, but you can pass the relevant location as needed, either with the ``--credential-file`` flag for the command-line app or as demonstrated below in a Python program.\n",
43
54
"\n",
44
55
"Both above examples require no special command-line arguments or in-program arguments. The credential parsing methods, unless otherwise specified, will look for a YAML key called `search_tweets_api`.\n",
45
56
"\n",
46
57
"\n",
47
-
"\n",
48
58
"For developers who have multiple endpoints and/or search products, you can keep all credentials in the same file and specify specific keys to use. `--credential-file-key` specifies this behavior in the command line app. An example:\n",
49
59
"\n",
50
60
"\n",
@@ -53,7 +63,10 @@
53
63
"search_tweets_30_day_dev:\n",
54
64
" account_type: premium\n",
55
65
" endpoint: <FULL_URL_OF_ENDPOINT>\n",
56
-
" bearer_token: <TOKEN>\n",
66
+
" consumer_key: <KEY>\n",
67
+
" consumer_secret: <SECRET>\n",
68
+
" (optional) bearer_token: <TOKEN>\n",
69
+
"\n",
57
70
"\n",
58
71
"search_tweets_30_day_prod:\n",
59
72
" account_type: premium\n",
@@ -87,6 +100,8 @@
87
100
"export SEARCHTWEETS_PASSWORD=\n",
88
101
"export SEARCHTWEETS_BEARER_TOKEN=\n",
89
102
"export SEARCHTWEETS_ACCOUNT_TYPE=\n",
103
+
"export SEARCHTWEETS_CONSUMER_KEY=\n",
104
+
"export SEARCHTWEETS_CONSUMER_SECRET=\n",
90
105
"```\n",
91
106
"\n",
92
107
"The `load_credentials` function will attempt to find these variables if it cannot load fields from the YAML file, and it will **overwrite any credentials from the YAML file that are present as environment variables** if they have been parsed. This behavior can be changed by setting the `load_credentials` parameter `env_overwrite` to `False`.\n",
0 commit comments