1
// Copyright 2013 Gary Burd
3
// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
// not use this file except in compliance with the License. You may obtain
5
// a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
// License for the specific language governing permissions and limitations
21
"github.com/garyburd/go-oauth/oauth"
29
var oauthClient = oauth.Client{
30
TemporaryCredentialRequestURI: "http://api.twitter.com/oauth/request_token",
31
ResourceOwnerAuthorizationURI: "http://api.twitter.com/oauth/authorize",
32
TokenRequestURI: "http://api.twitter.com/oauth/access_token",
35
var credPath = flag.String("config", "config.json", "Path to configuration file containing the application's credentials.")
37
func readCredentials() error {
38
b, err := ioutil.ReadFile(*credPath)
42
return json.Unmarshal(b, &oauthClient.Credentials)
46
if err := readCredentials(); err != nil {
50
tempCred, err := oauthClient.RequestTemporaryCredentials(http.DefaultClient, "oob", nil)
52
log.Fatal("RequestTemporaryCredentials:", err)
55
u := oauthClient.AuthorizationURL(tempCred, nil)
57
fmt.Printf("1. Go to %s\n2. Authorize the application\n3. Enter verification code:\n", u)
62
tokenCred, _, err := oauthClient.RequestToken(http.DefaultClient, tempCred, code)
67
resp, err := oauthClient.Get(http.DefaultClient, tokenCred,
68
"http://api.twitter.com/1.1/statuses/home_timeline.json", nil)
72
defer resp.Body.Close()
73
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {