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
{{ message }}
This repository was archived by the owner on Nov 7, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -247,13 +247,17 @@ import (
247
247
"golang.org/x/oauth2/clientcredentials"
248
248
)
249
249
250
+
// oauth2 configures a client that uses app credentials to keep a fresh token
250
251
config:= &clientcredentials.Config{
251
-
ClientID: consumerKey,
252
-
ClientSecret: consumerSecret,
252
+
ClientID: "consumerKey",
253
+
ClientSecret: "consumerSecret",
253
254
TokenURL: "https://api.twitter.com/oauth2/token",
254
255
}
256
+
// http.Client will automatically authorize Requests
255
257
httpClient:= config.Client(oauth2.NoContext)
256
-
twClient:= twitter.NewClient(httpClient)
258
+
259
+
// Twitter client
260
+
client:= twitter.NewClient(httpClient)
257
261
```
258
262
259
263
To implement Login with Twitter for web or mobile, see the gologin [package](https://github.com/dghubble/gologin) and [examples](https://github.com/dghubble/gologin/tree/master/examples/twitter).
Copy file name to clipboardExpand all lines: examples/README.md
+21-11Lines changed: 21 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,32 +11,42 @@ Get the dependencies and examples
11
11
A user access token (OAuth1) grants a consumer application access to a user's Twitter resources.
12
12
13
13
Setup an OAuth1 `http.Client` with the consumer key and secret and oauth token and secret.
14
-
15
-
export TWITTER_CONSUMER_KEY=xxx
16
-
export TWITTER_CONSUMER_SECRET=xxx
17
-
export TWITTER_ACCESS_TOKEN=xxx
18
-
export TWITTER_ACCESS_SECRET=xxx
14
+
```
15
+
export TWITTER_CONSUMER_KEY=xxx
16
+
export TWITTER_CONSUMER_SECRET=xxx
17
+
export TWITTER_ACCESS_TOKEN=xxx
18
+
export TWITTER_ACCESS_SECRET=xxx
19
+
```
19
20
20
21
To make requests as an application, on behalf of a user, create a `twitter``Client` to get the home timeline, mention timeline, and more (example will **not** post Tweets).
21
22
22
-
go run user-auth.go
23
+
```
24
+
go run user-auth.go
25
+
```
23
26
24
27
## App Auth (OAuth2)
25
28
26
29
An application access token (OAuth2) allows an application to make Twitter API requests for public content, with rate limits counting against the app itself. App auth requests can be made to API endpoints which do not require a user context.
27
30
28
-
Setup an OAuth2 `http.Client` with the Twitter application access token.
31
+
Setup an OAuth2 `http.Client` with the Twitter consumer key and secret.
29
32
30
-
export TWITTER_APP_ACCESS_TOKEN=xxx
33
+
```
34
+
export TWITTER_CONSUMER_KEY=xxx
35
+
export TWITTER_CONSUMER_SECRET=xxx
36
+
```
31
37
32
38
To make requests as an application, create a `twitter``Client` and get public Tweets or timelines or other public content.
33
39
34
-
go run app-auth.go
40
+
```
41
+
go run app-auth.go
42
+
```
35
43
36
44
## Streaming API
37
45
38
46
A user access token (OAuth1) is required for Streaming API requests. See above.
39
47
40
-
go run streaming.go
48
+
```
49
+
go run streaming.go
50
+
```
41
51
42
-
Hit CTRL-C to stop streaming. Uncomment different examples in code to try different streams.
52
+
Hit CTRL-C to stop streaming. Uncomment different examples in code to try different streams.
0 commit comments