-
Notifications
You must be signed in to change notification settings - Fork 13
/
desktop_client.go
60 lines (49 loc) · 1.25 KB
/
desktop_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package twitter
import (
"fmt"
"log"
"github.com/mrjones/oauth"
)
func NewDesktopClient(consumerKey, consumerSecret string) *DesktopClient {
newDesktop := new(DesktopClient)
newDesktop.OAuthConsumer = oauth.NewConsumer(
consumerKey,
consumerSecret,
oauth.ServiceProvider{
RequestTokenUrl: OAUTH_REQUES_TOKEN,
AuthorizeTokenUrl: OAUTH_AUTH_TOKEN,
AccessTokenUrl: OAUTH_ACCESS_TOKEN,
},
)
//Enable debug info
newDesktop.OAuthConsumer.Debug(false)
return newDesktop
}
type DesktopClient struct {
Client
OAuthConsumer *oauth.Consumer
}
func (d *DesktopClient) DoAuth() error {
requestToken, u, err := d.OAuthConsumer.GetRequestTokenAndUrl("oob")
fmt.Println("rest token=", requestToken, " err=", err)
if err != nil {
log.Println(err)
return err
}
fmt.Println("(1) Go to: " + u)
fmt.Println("(2) Grant access, you should get back a verification code.")
fmt.Println("(3) Enter that verification code here: ")
verificationCode := ""
fmt.Scanln(&verificationCode)
accessToken, err := d.OAuthConsumer.AuthorizeToken(requestToken, verificationCode)
if err != nil {
log.Println(err)
return err
}
d.HttpConn, err = d.OAuthConsumer.MakeHttpClient(accessToken)
if err != nil {
log.Println(err)
return err
}
return err
}