Skip to content

Commit 88fd2a7

Browse files
Twitter API with Tweepy
1 parent bd9014e commit 88fd2a7

9 files changed

+3637
-0
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import tweepy\n",
10+
"import webbrowser\n",
11+
"import time"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 14,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"consumer_key = \"82sYf9hQSpGNuc9K8wTVGOqz0\"\n",
21+
"consumer_secret = \"6tf3Iu3eiaLesTA2yxZPD2Ht7cJxs4Nk8vxBH0ltAPD3enaNGK\""
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 15,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"callback_uri = 'oob' # https://cfe.sh/twitter/callback"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 16,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"name": "stdout",
40+
"output_type": "stream",
41+
"text": [
42+
"https://api.twitter.com/oauth/authorize?oauth_token=s1HuAwAAAAAAjsBpAAABceMY7y0\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback_uri)\n",
48+
"redirect_url = auth.get_authorization_url()\n",
49+
"print(redirect_url)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": []
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 17,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"data": {
66+
"text/plain": [
67+
"True"
68+
]
69+
},
70+
"execution_count": 17,
71+
"metadata": {},
72+
"output_type": "execute_result"
73+
}
74+
],
75+
"source": [
76+
"webbrowser.open(redirect_url)"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 19,
82+
"metadata": {},
83+
"outputs": [
84+
{
85+
"name": "stdout",
86+
"output_type": "stream",
87+
"text": [
88+
"What's the pin value? 6140001\n"
89+
]
90+
}
91+
],
92+
"source": [
93+
"user_pint_input = input(\"What's the pin value? \")"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": 20,
99+
"metadata": {},
100+
"outputs": [
101+
{
102+
"data": {
103+
"text/plain": [
104+
"'6140001'"
105+
]
106+
},
107+
"execution_count": 20,
108+
"metadata": {},
109+
"output_type": "execute_result"
110+
}
111+
],
112+
"source": [
113+
"user_pint_input"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 21,
119+
"metadata": {},
120+
"outputs": [
121+
{
122+
"data": {
123+
"text/plain": [
124+
"('4730574793-fa9oFomAHt4K4iw5uaWRaG0iw1OxCUu47ieHm5Q',\n",
125+
" 'fOC4HAcXzr35dl8gZdzZdkC0dBr7l26pOvJv56oqF4yTf')"
126+
]
127+
},
128+
"execution_count": 21,
129+
"metadata": {},
130+
"output_type": "execute_result"
131+
}
132+
],
133+
"source": [
134+
"auth.get_access_token(user_pint_input)"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 13,
140+
"metadata": {},
141+
"outputs": [
142+
{
143+
"name": "stdout",
144+
"output_type": "stream",
145+
"text": [
146+
"4730574793-fa9oFomAHt4K4iw5uaWRaG0iw1OxCUu47ieHm5Q fOC4HAcXzr35dl8gZdzZdkC0dBr7l26pOvJv56oqF4yTf\n"
147+
]
148+
}
149+
],
150+
"source": [
151+
"print(auth.access_token, auth.access_token_secret)"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": 22,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": [
160+
"api = tweepy.API(auth)"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": 23,
166+
"metadata": {},
167+
"outputs": [],
168+
"source": [
169+
"me = api.me()"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": 24,
175+
"metadata": {},
176+
"outputs": [
177+
{
178+
"name": "stdout",
179+
"output_type": "stream",
180+
"text": [
181+
"joincfe\n"
182+
]
183+
}
184+
],
185+
"source": [
186+
"print(me.screen_name)"
187+
]
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": null,
192+
"metadata": {},
193+
"outputs": [],
194+
"source": []
195+
}
196+
],
197+
"metadata": {
198+
"kernelspec": {
199+
"display_name": "Python 3",
200+
"language": "python",
201+
"name": "python3"
202+
},
203+
"language_info": {
204+
"codemirror_mode": {
205+
"name": "ipython",
206+
"version": 3
207+
},
208+
"file_extension": ".py",
209+
"mimetype": "text/x-python",
210+
"name": "python",
211+
"nbconvert_exporter": "python",
212+
"pygments_lexer": "ipython3",
213+
"version": "3.8.2"
214+
}
215+
},
216+
"nbformat": 4,
217+
"nbformat_minor": 4
218+
}

0 commit comments

Comments
 (0)