-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 70 list follows api (#103)
* add user follow list manage * get followed lists * get list folloers * typo * added unit tests * added examples * updated readme * added the comments
- Loading branch information
1 parent
d5d4d6a
commit 3f09833
Showing
11 changed files
with
1,062 additions
and
2 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,55 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
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 tweet ids. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
listID := flag.String("list_id", "", "list id") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
|
||
opts := twitter.ListUserFollowersOpts{ | ||
Expansions: []twitter.Expansion{twitter.ExpansionPinnedTweetID}, | ||
MaxResults: 5, | ||
} | ||
|
||
fmt.Println("Callout to list members callout") | ||
|
||
listResponse, err := client.ListUserFollowers(context.Background(), *listID, opts) | ||
if err != nil { | ||
log.Panicf("list members error: %v", err) | ||
} | ||
|
||
enc, err := json.MarshalIndent(listResponse, "", " ") | ||
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,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
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 tweet ids. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
userID := flag.String("user_id", "", "user id") | ||
listID := flag.String("list_id", "", "list id") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
|
||
fmt.Println("Callout to user follow list callout") | ||
|
||
listResponse, err := client.UserFollowList(context.Background(), *userID, *listID) | ||
if err != nil { | ||
log.Panicf(" user follow list error: %v", err) | ||
} | ||
|
||
enc, err := json.MarshalIndent(listResponse, "", " ") | ||
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,55 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
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 tweet ids. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
userID := flag.String("user_id", "", "user id") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
opts := twitter.UserFollowedListsOpts{ | ||
Expansions: []twitter.Expansion{twitter.ExpansionOwnerID}, | ||
ListFields: []twitter.ListField{twitter.ListFieldFollowerCount}, | ||
UserFields: []twitter.UserField{twitter.UserFieldCreatedAt}, | ||
} | ||
|
||
fmt.Println("Callout to user followed list lookup callout") | ||
|
||
listResponse, err := client.UserFollowedLists(context.Background(), *userID, opts) | ||
if err != nil { | ||
log.Panicf(" user followed list lookup error: %v", err) | ||
} | ||
|
||
enc, err := json.MarshalIndent(listResponse, "", " ") | ||
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,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
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 tweet ids. | ||
**/ | ||
func main() { | ||
token := flag.String("token", "", "twitter API token") | ||
userID := flag.String("user_id", "", "user id") | ||
listID := flag.String("list_id", "", "list id") | ||
flag.Parse() | ||
|
||
client := &twitter.Client{ | ||
Authorizer: authorize{ | ||
Token: *token, | ||
}, | ||
Client: http.DefaultClient, | ||
Host: "https://api.twitter.com", | ||
} | ||
|
||
fmt.Println("Callout to user unfollow list callout") | ||
|
||
listResponse, err := client.UserUnfollowList(context.Background(), *userID, *listID) | ||
if err != nil { | ||
log.Panicf(" user unfollow list error: %v", err) | ||
} | ||
|
||
enc, err := json.MarshalIndent(listResponse, "", " ") | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
fmt.Println(string(enc)) | ||
} |
Oops, something went wrong.