Skip to content

Commit

Permalink
Implement User Time by two func
Browse files Browse the repository at this point in the history
  • Loading branch information
kkdai committed Oct 30, 2022
1 parent 41e9796 commit a82eef3
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 9 deletions.
37 changes: 28 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ const (
OAUTH_ACCESS_TOKEN string = "https://api.twitter.com/oauth/access_token"

//List API URLs
API_BASE string = "https://api.twitter.com/1.1/"
API_TIMELINE string = API_BASE + "statuses/home_timeline.json"
API_MENTIONS_TIMMELINE string = API_BASE + "statuses/mentions_timeline.json"
API_FOLLOWERS_IDS string = API_BASE + "followers/ids.json"
API_FOLLOWERS_LIST string = API_BASE + "followers/list.json"
API_FOLLOWER_INFO string = API_BASE + "users/show.json"
API_BASE string = "https://api.twitter.com/1.1/"
API_TIMELINE string = API_BASE + "statuses/home_timeline.json"
API_MENTIONS_TIMELINE string = API_BASE + "statuses/mentions_timeline.json"
API_USER_TIMELINE string = API_BASE + "statuses/user_timeline.json"
API_FOLLOWERS_IDS string = API_BASE + "followers/ids.json"
API_FOLLOWERS_LIST string = API_BASE + "followers/list.json"
API_FOLLOWER_INFO string = API_BASE + "users/show.json"
)

type Client struct {
Expand All @@ -47,19 +48,37 @@ func (c *Client) BasicQuery(queryString string) ([]byte, error) {
return bits, err
}

// User Timeline by UserID
func (c *Client) QueryUserTimelineByUserID(user_id string) (UserTimeline, []byte, error) {
requesURL := fmt.Sprintf("%s?user_id=%s", API_USER_TIMELINE, user_id)
data, err := c.BasicQuery(requesURL)
ret := UserTimeline{}
err = json.Unmarshal(data, &ret)
return ret, data, err
}

// User Timeline by ScreenName
func (c *Client) QueryUserTimelineByScreenName(ScreeName string) (UserTimeline, []byte, error) {
requesURL := fmt.Sprintf("%s?screen_name=%s", API_USER_TIMELINE, ScreeName)
data, err := c.BasicQuery(requesURL)
ret := UserTimeline{}
err = json.Unmarshal(data, &ret)
return ret, data, err
}

// Mentions Timeline.
func (c *Client) QueryMentionsTimeline(count int) (TimelineTweets, []byte, error) {
requesURL := fmt.Sprintf("%s?count=%d", API_TIMELINE, count)
requesURL := fmt.Sprintf("%s?count=%d", API_MENTIONS_TIMELINE, count)
data, err := c.BasicQuery(requesURL)
ret := TimelineTweets{}
err = json.Unmarshal(data, &ret)
return ret, data, err
}

func (c *Client) QueryTimeLine(count int) (TimelineTweets, []byte, error) {
func (c *Client) QueryTimeLine(count int) (MentionsTimeline, []byte, error) {
requesURL := fmt.Sprintf("%s?count=%d", API_TIMELINE, count)
data, err := c.BasicQuery(requesURL)
ret := TimelineTweets{}
ret := MentionsTimeline{}
err = json.Unmarshal(data, &ret)
return ret, data, err
}
Expand Down
193 changes: 193 additions & 0 deletions response_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,199 @@ type Followers struct {
PreviousCursorStr string `json:"previous_cursor_str"`
}

type UserTimeline []struct {
CreatedAt string `json:"created_at"`
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Text string `json:"text"`
Truncated bool `json:"truncated"`
Entities struct {
Hashtags []interface{} `json:"hashtags"`
Symbols []interface{} `json:"symbols"`
UserMentions []struct {
ScreenName string `json:"screen_name"`
Name string `json:"name"`
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Indices []int `json:"indices"`
} `json:"user_mentions"`
Urls []struct {
URL string `json:"url"`
ExpandedURL string `json:"expanded_url"`
DisplayURL string `json:"display_url"`
Indices []int `json:"indices"`
} `json:"urls"`
} `json:"entities"`
Source string `json:"source"`
InReplyToStatusID interface{} `json:"in_reply_to_status_id"`
InReplyToStatusIDStr interface{} `json:"in_reply_to_status_id_str"`
InReplyToUserID interface{} `json:"in_reply_to_user_id"`
InReplyToUserIDStr interface{} `json:"in_reply_to_user_id_str"`
InReplyToScreenName interface{} `json:"in_reply_to_screen_name"`
User struct {
ID int `json:"id"`
IDStr string `json:"id_str"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
Location string `json:"location"`
Description string `json:"description"`
URL string `json:"url"`
Entities struct {
URL struct {
Urls []struct {
URL string `json:"url"`
ExpandedURL string `json:"expanded_url"`
DisplayURL string `json:"display_url"`
Indices []int `json:"indices"`
} `json:"urls"`
} `json:"url"`
Description struct {
Urls []interface{} `json:"urls"`
} `json:"description"`
} `json:"entities"`
Protected bool `json:"protected"`
FollowersCount int `json:"followers_count"`
FriendsCount int `json:"friends_count"`
ListedCount int `json:"listed_count"`
CreatedAt string `json:"created_at"`
FavouritesCount int `json:"favourites_count"`
UtcOffset int `json:"utc_offset"`
TimeZone string `json:"time_zone"`
GeoEnabled bool `json:"geo_enabled"`
Verified bool `json:"verified"`
StatusesCount int `json:"statuses_count"`
Lang string `json:"lang"`
ContributorsEnabled bool `json:"contributors_enabled"`
IsTranslator bool `json:"is_translator"`
IsTranslationEnabled bool `json:"is_translation_enabled"`
ProfileBackgroundColor string `json:"profile_background_color"`
ProfileBackgroundImageURL string `json:"profile_background_image_url"`
ProfileBackgroundImageURLHTTPS string `json:"profile_background_image_url_https"`
ProfileBackgroundTile bool `json:"profile_background_tile"`
ProfileImageURL string `json:"profile_image_url"`
ProfileImageURLHTTPS string `json:"profile_image_url_https"`
ProfileBannerURL string `json:"profile_banner_url"`
ProfileLinkColor string `json:"profile_link_color"`
ProfileSidebarBorderColor string `json:"profile_sidebar_border_color"`
ProfileSidebarFillColor string `json:"profile_sidebar_fill_color"`
ProfileTextColor string `json:"profile_text_color"`
ProfileUseBackgroundImage bool `json:"profile_use_background_image"`
HasExtendedProfile bool `json:"has_extended_profile"`
DefaultProfile bool `json:"default_profile"`
DefaultProfileImage bool `json:"default_profile_image"`
Following bool `json:"following"`
FollowRequestSent bool `json:"follow_request_sent"`
Notifications bool `json:"notifications"`
TranslatorType string `json:"translator_type"`
} `json:"user"`
Geo interface{} `json:"geo"`
Coordinates interface{} `json:"coordinates"`
Place interface{} `json:"place"`
Contributors interface{} `json:"contributors"`
RetweetedStatus struct {
CreatedAt string `json:"created_at"`
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Text string `json:"text"`
Truncated bool `json:"truncated"`
Entities struct {
Hashtags []interface{} `json:"hashtags"`
Symbols []interface{} `json:"symbols"`
UserMentions []interface{} `json:"user_mentions"`
Urls []struct {
URL string `json:"url"`
ExpandedURL string `json:"expanded_url"`
DisplayURL string `json:"display_url"`
Indices []int `json:"indices"`
} `json:"urls"`
} `json:"entities"`
Source string `json:"source"`
InReplyToStatusID interface{} `json:"in_reply_to_status_id"`
InReplyToStatusIDStr interface{} `json:"in_reply_to_status_id_str"`
InReplyToUserID interface{} `json:"in_reply_to_user_id"`
InReplyToUserIDStr interface{} `json:"in_reply_to_user_id_str"`
InReplyToScreenName interface{} `json:"in_reply_to_screen_name"`
User struct {
ID int64 `json:"id"`
IDStr string `json:"id_str"`
Name string `json:"name"`
ScreenName string `json:"screen_name"`
Location string `json:"location"`
Description string `json:"description"`
URL string `json:"url"`
Entities struct {
URL struct {
Urls []struct {
URL string `json:"url"`
ExpandedURL string `json:"expanded_url"`
DisplayURL string `json:"display_url"`
Indices []int `json:"indices"`
} `json:"urls"`
} `json:"url"`
Description struct {
Urls []struct {
URL string `json:"url"`
ExpandedURL string `json:"expanded_url"`
DisplayURL string `json:"display_url"`
Indices []int `json:"indices"`
} `json:"urls"`
} `json:"description"`
} `json:"entities"`
Protected bool `json:"protected"`
FollowersCount int `json:"followers_count"`
FriendsCount int `json:"friends_count"`
ListedCount int `json:"listed_count"`
CreatedAt string `json:"created_at"`
FavouritesCount int `json:"favourites_count"`
UtcOffset int `json:"utc_offset"`
TimeZone string `json:"time_zone"`
GeoEnabled bool `json:"geo_enabled"`
Verified bool `json:"verified"`
StatusesCount int `json:"statuses_count"`
Lang string `json:"lang"`
ContributorsEnabled bool `json:"contributors_enabled"`
IsTranslator bool `json:"is_translator"`
IsTranslationEnabled bool `json:"is_translation_enabled"`
ProfileBackgroundColor string `json:"profile_background_color"`
ProfileBackgroundImageURL string `json:"profile_background_image_url"`
ProfileBackgroundImageURLHTTPS string `json:"profile_background_image_url_https"`
ProfileBackgroundTile bool `json:"profile_background_tile"`
ProfileImageURL string `json:"profile_image_url"`
ProfileImageURLHTTPS string `json:"profile_image_url_https"`
ProfileBannerURL string `json:"profile_banner_url"`
ProfileLinkColor string `json:"profile_link_color"`
ProfileSidebarBorderColor string `json:"profile_sidebar_border_color"`
ProfileSidebarFillColor string `json:"profile_sidebar_fill_color"`
ProfileTextColor string `json:"profile_text_color"`
ProfileUseBackgroundImage bool `json:"profile_use_background_image"`
HasExtendedProfile bool `json:"has_extended_profile"`
DefaultProfile bool `json:"default_profile"`
DefaultProfileImage bool `json:"default_profile_image"`
Following bool `json:"following"`
FollowRequestSent bool `json:"follow_request_sent"`
Notifications bool `json:"notifications"`
TranslatorType string `json:"translator_type"`
} `json:"user"`
Geo interface{} `json:"geo"`
Coordinates interface{} `json:"coordinates"`
Place interface{} `json:"place"`
Contributors interface{} `json:"contributors"`
IsQuoteStatus bool `json:"is_quote_status"`
RetweetCount int `json:"retweet_count"`
FavoriteCount int `json:"favorite_count"`
Favorited bool `json:"favorited"`
Retweeted bool `json:"retweeted"`
PossiblySensitive bool `json:"possibly_sensitive"`
Lang string `json:"lang"`
} `json:"retweeted_status"`
IsQuoteStatus bool `json:"is_quote_status"`
RetweetCount int `json:"retweet_count"`
FavoriteCount int `json:"favorite_count"`
Favorited bool `json:"favorited"`
Retweeted bool `json:"retweeted"`
PossiblySensitive bool `json:"possibly_sensitive,omitempty"`
Lang string `json:"lang"`
}
type UserDetail struct {
ContributorsEnabled bool `json:"contributors_enabled"`
CreatedAt string `json:"created_at"`
Expand Down

0 comments on commit a82eef3

Please sign in to comment.