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
Copy file name to clipboardExpand all lines: docs/usage/advanced_usage.rst
+61Lines changed: 61 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -40,5 +40,66 @@ That being said, Twython offers a generator for search results and can be access
40
40
for result in search:
41
41
print result
42
42
43
+
Manipulate the Request (headers, proxies, etc.)
44
+
-----------------------------------------------
45
+
46
+
There are times when you may want to turn SSL verification off, send custom headers, or add proxies for the request to go through.
47
+
48
+
Twython uses the `requests <http://python-requests.org>`_ library to make API calls to Twitter. ``requests`` accepts a few parameters to allow developers to manipulate the acutal HTTP request.
49
+
50
+
Here is an example of sending custom headers to a Twitter API request:
51
+
52
+
::
53
+
54
+
from twython import Twython
55
+
56
+
client_args = {
57
+
'headers': {
58
+
'User-Agent': 'My App Name'
59
+
}
60
+
}
61
+
62
+
twitter = Twython(APP_KEY, APP_SECRET
63
+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
64
+
client_args=client_args)
65
+
66
+
Here is an example of sending the request through proxies:
67
+
68
+
::
69
+
70
+
from twython import Twython
71
+
72
+
client_args = {
73
+
'proxies': {
74
+
'http': '10.0.10.1:8000',
75
+
'https': '10.0.10.1:8001',
76
+
}
77
+
}
78
+
79
+
twitter = Twython(APP_KEY, APP_SECRET
80
+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
81
+
client_args=client_args)
82
+
83
+
or both (and set a timeout variable):
84
+
85
+
::
86
+
87
+
from twython import Twython
88
+
89
+
client_args = {
90
+
'headers': {
91
+
'User-Agent': 'My App Name'
92
+
},
93
+
'proxies': {
94
+
'http': '10.0.10.1:8000',
95
+
'https': '10.0.10.1:8001',
96
+
}
97
+
'timeout': 300,
98
+
}
99
+
100
+
twitter = Twython(APP_KEY, APP_SECRET
101
+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
102
+
client_args=client_args)
103
+
43
104
44
105
So now you can authenticate, update your status (with or without an image), search Twitter, and a few other things! Good luck!
0 commit comments