-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added the user by id lookup (standard) * add the user by username lookup * added user dictionary * added tweet raw dictionary * added the user raw dictionary * added examples * updated the readme * fixed the golint suggestions * corrected example comments
- Loading branch information
1 parent
e5be3d8
commit df4a984
Showing
14 changed files
with
1,242 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
|
||
twitter "github.com/g8rswimmer/go-twitter/v2" | ||
) | ||
|
||
type authorize struct { | ||
Token string | ||
} | ||
|
||
func (a authorize) Add(req *http.Request) { | ||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token)) | ||
} | ||
|
||
/** | ||
In order to run, the user will need to provide the bearer token and the list of user ids. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
ids := flag.String("ids", "", "user ids") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
opts := twitter.UserLookupOpts{ | ||
Expansions: []twitter.Expansion{twitter.ExpansionPinnedTweetID}, | ||
} | ||
|
||
fmt.Println("Callout to user lookup callout") | ||
|
||
userResponse, err := client.UserLookup(context.Background(), strings.Split(*ids, ","), opts) | ||
if err != nil { | ||
log.Panicf("user lookup error: %v", err) | ||
} | ||
|
||
dictionaries := userResponse.Raw.UserDictionaries() | ||
|
||
enc, err := json.MarshalIndent(dictionaries, "", " ") | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
fmt.Println(string(enc)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"strings" | ||
|
||
twitter "github.com/g8rswimmer/go-twitter/v2" | ||
) | ||
|
||
type authorize struct { | ||
Token string | ||
} | ||
|
||
func (a authorize) Add(req *http.Request) { | ||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token)) | ||
} | ||
|
||
/** | ||
In order to run, the user will need to provide the bearer token and the list of usernames. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
names := flag.String("names", "", "user names") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
opts := twitter.UserLookupOpts{ | ||
Expansions: []twitter.Expansion{twitter.ExpansionPinnedTweetID}, | ||
} | ||
|
||
fmt.Println("Callout to user lookup callout") | ||
|
||
userResponse, err := client.UserNameLookup(context.Background(), strings.Split(*names, ","), opts) | ||
if err != nil { | ||
log.Panicf("user lookup error: %v", err) | ||
} | ||
|
||
dictionaries := userResponse.Raw.UserDictionaries() | ||
|
||
enc, err := json.MarshalIndent(dictionaries, "", " ") | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
fmt.Println(string(enc)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.