tweetlib.v2: gopkg.in/tweetlib.v2 Index | Files

package tweetlib

import "gopkg.in/tweetlib.v2"

A fully OAuth-authenticated implementation of Twitter's REST API v1.1

See https:dev.twitter.com/docs/api/

Usage example:

  import "gopkg.in/tweetlib.v2"

  config := &tweetlib.Config{
  	ConsumerKey: "your-consumer-key",
  	ConsumerSecret: "your-consumer-secret",
	Callback: "http:www.my-app.com/my-callback",
  }
  token := &tweetlib.Token{
        OAuthSecret: "your-oauth-secret",
        OAuthToken: "your-oauth-token",
  }
  tr := &tweetlib.Transport{
	Config: config,
        Token: token,
  }

  client, _ := tweetlib.New(tr.Client())
  client.Tweets.Update("Hello, world")

Authentication

Twitter uses OAUTH 1.0a for authentication and tweetlib supports the 3-legged authorization method.

See https://dev.twitter.com/docs/auth/3-legged-authorization

1. Setup a Config structure with the Consuler Key and Secret found on your application's page. You can create new applications by visiting http://dev.twitter.com/apps/new. Twitter also requires a callback URL that will receive Twitter's token

    config := &tweetlib.Config{
        ConsumerKey: "your-consumer-key",
	ConsumerSecret: "your-consumer-secret",
	Callback: "http://www.my-app.com/my-callback",
    }

2. Populate a tweetlibTransport structure with the Config from the previous step and, for now, an empty Token

    tr := &tweetlib.Transport{
	    Config: config,
            Token: &tweetlib.Token{}
    }

2a. (Optional) tweetlib.Transport uses the http package to talk to Twitter by default. This may not be possible or desirable. For example, if the Client is to be used in a Google Appengine app, it becomes necessary to change the underlying transport to be used. E.g.:

tr.Transport = &urlfetch.Transport{Context: c}

3. Not it's possible to request the temporary token. This will start the little Oauth dance with Twitter

tt, err := tr.TempToken()

4. With the tweetlib.TempToken ready, now it's time to request the user to authorize your application. This is done by redirecting the user to the URL returned by tweetlib.TempToken.AuthURL(). (Note that you must save the temporary token as it will be necessary later to request the permanent token)

authorizationURL := tt.AUthURL()
// save tt so it is accessible from the callback later
// redirect the user to authorizationURL...

5. The user will be promted by Twitter to authorize your application. If they authorize it, Twitter will call your callback as set in step 1. Twitter will issue a GET request to your callback with two parameters:

oauth_token      same as your TempToken.Token
oauth_verifier   A code that will be used to verify that your call back
                 was valid and received information.

6. Finally, you'll request the permanent token from Twitter

tok, err := tr.AccessToken(tt, oauth_verifier)

Note that you do not need to update your tweetlib.Transport.Token with the new token, as this is done automatically, meaning you can immediatly start making API calls with the same transport.

That said, you must save the token for future use so you don't have to go through all this dance again each time. Next time you need to make calls on behalf of a user you already have a token for, you simply set the Transport with the saved token.

    tr := &tweetlib.Transport{
	    Config: config,
	    Token: savedUserToken,
    }

Application Only Authentication

Using the Twitter API we can obtain an authentication token for only our application

a := &tweetlib.ApplicationOnly{
   Client: &http.Client{},  // Or whatever client you wish to use
   Config: config,
}
token, err := a.GetToken()

Yes it's that easy. Now you have a token that you can use to make API calls

Invalidating An Application Authentication Token

We can invalidate a previously obtained application only token by passing it to the InvalidateToken function

token := "AAAAAAAAAAAAAAAAAAAAAAA%2FAAAAAAAAAAAA"
a := &tweetlib.ApplicationOnly{
   Client: &http.Client{},
   Config: config,
}
a.InvalidateToken(token)

Making API calls

For making calls based off a users account, making an API call is trivial once authentication is set up. It all starts with getting an API Client object:

   oauthClient := (&tweetlib.Transport{config, token, nil}).Client()
   client, err := tweetlib.New(oauthClient)
   if err != nil {
	   panic(err)
   }

For making calls for applications only, we can use our previously obtained authentication token and pass it to the application-only client constructor. Unlike utilizing user authenticated APIs, we do not need to use any custom instances of http.Client

token, err := a.GetToken()
client, err := tweetlib.NewApplicationClient(&http.Client{}, token)

Once you have the client, you can make API calls easily. For example, to post a tweet as the authenticating user

tweet, err := client.Tweets.Update("Hello, world", nil)

The vast majority of API calls to the Twitter REST API takes one or two required parameters along with any number of optional ones. For example, when updating the status, it is possible to attached geographical coordinates to it via the 'lat' and 'long' optional parameters.

To provide optional parameters, use tweetlib.Optionals

opts := tweetlib.NewOptionals()
opts.Add("lat", 37.7821120598956)
opts.Add("long", -122.400612831116)
tweet, err := client.Tweets.Update("Hello, world", opts)

There's also two ways of making arbitrary API calls. This is useful when you need to call a new API that is not directly supported by tweetlib's utility functions or maybe you want better control of the response objects.

The first way is using Client.Call like this:

var user User
opts := NewOptionals()
opts.Add("screen_name", "sometwitteruser")
err := client.Call("GET", "users/show", opts, &user)

Client.Call will try to unmarshal the response returned from Twitter. If however you wish to do it yourself or maybe not use the types defined by tweetlib (User, Tweet, etc), you can use CallJSON instead:

rawJSON, err := client.CallJSON("GET", "users/show", opts)
// rawJSON now has the JSON response from Twitter

These two functions are usually internally by the many helper functions defined in tweetlib and also add flexibility to

tweetlib - A fully oauth-authenticated Go Twitter library

Copyright 2011 The Tweetlib Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Package Files

account.go client.go dm.go doc.go error.go friends.go help.go list.go oauth.go search.go tweets.go types.go user.go

type AccountService Uses

type AccountService struct {
    *Client
}

Groups account-related functions

func (*AccountService) EnableSMS Uses

func (ag *AccountService) EnableSMS(enable bool) (err error)

Enables/disables SMS delivery See https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device

func (*AccountService) Settings Uses

func (ag *AccountService) Settings() (settings *AccountSettings, err error)

Returns settings (including current trend, geo and sleep time information) for the authenticating user See https://dev.twitter.com/docs/api/1.1/get/account/settings

func (*AccountService) UpdateProfile Uses

func (ag *AccountService) UpdateProfile(opts *Optionals) (user *User, err error)

Sets values that users are able to set under the "Account" tab of their settings page. Only the parameters specified will be updated. See https://dev.twitter.com/docs/api/1.1/post/account/update_profile

func (*AccountService) UpdateProfileBackgroundImage Uses

func (ag *AccountService) UpdateProfileBackgroundImage(image []byte, opts *Optionals) (user *User, err error)

Updates the authenticating user's profile background image. Passing an empty []byte as image will disable the current background image. https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image

func (*AccountService) UpdateProfileColors Uses

func (ag *AccountService) UpdateProfileColors(opts *Optionals) (user *User, err error)

Sets one or more hex values that control the color scheme of the authenticating user's profile page on twitter.com. Each parameter's value must be a valid hexidecimal value, and may be either three or six characters (ex: #fff or #ffffff).

func (*AccountService) UpdateProfileImage Uses

func (ag *AccountService) UpdateProfileImage(image []byte, opts *Optionals) (user *User, err error)

Updates the authenticating user's profile image. The image parameter should be the raw data from the image file, not a path or URL See https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image

func (*AccountService) UpdateSettings Uses

func (ag *AccountService) UpdateSettings(opts *Optionals) (newSettings *AccountSettings, err error)

Update authenticating user's settings. See https://dev.twitter.com/docs/api/1.1/post/account/settings

func (*AccountService) VerifyCredentials Uses

func (ag *AccountService) VerifyCredentials(opts *Optionals) (user *User, err error)

Helper function to verify if credentials are valid. Returns the user object if they are. See https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials

type AccountSettings Uses

type AccountSettings struct {
    AlwaysUseHttps      bool   `json:"always_use_https"`
    DiscoverableByEmail bool   `json:"discoverable_by_email"`
    GeoEnabled          bool   `json:"geo_enabled"`
    Language            string `json:"language"`
    Protected           bool   `json:"protected"`
    ScreenName          string `json:"screen_name"`
    ShowAllInlineMedia  bool   `json:"show_all_inline_media"`
    SleepTime           struct {
        Enabled   bool `json:"enabled"`
        EndTime   int
        StartTime int
    }   `json:"sleep_time"`
    TimeZone struct {
        Name       string `json:"name"`
        TzinfoName string `json:"tzinfo_name"`
        UtcOffset  int64
    }   `json:"time_zone"`
    TrendLocation []struct {
        Country     string `json:"country"`
        CountryCode string `json:"countryCode"`
        Name        string `json:"name"`
        ParentId    int64  `json:"parentid"`
        PlaceType   struct {
            Code int64  `json:"code"`
            Name string `json:"name"`
        }
        Url   string `json:"url"`
        WoeId int64  `json:"woeid"`
    }   `json:"trend_location"`
    UseCookiePersonalization bool `json:"use_cookie_personalization"`
}

Settings for the authenticated account

type ApplicationOAuthError Uses

type ApplicationOAuthError struct {
    // contains filtered or unexported fields
}

Represents an error generated when attempting to gain/invalidate an application-only oauth token

func NoBearerTokenError Uses

func NoBearerTokenError() *ApplicationOAuthError

func (*ApplicationOAuthError) Error Uses

func (e *ApplicationOAuthError) Error() string

type ApplicationOnly Uses

type ApplicationOnly struct {
    *http.Client
    *Config
}

func (*ApplicationOnly) GetToken Uses

func (a *ApplicationOnly) GetToken() (string, error)

Gets a token for only the application desiring to make API calls. The full step breakdown can be found at https://dev.twitter.com/docs/auth/application-only-auth.

func (*ApplicationOnly) InvalidateToken Uses

func (a *ApplicationOnly) InvalidateToken(token string) error

Invalidate a previously obtained authentication token

type ApplicationTokenResponse Uses

type ApplicationTokenResponse struct {
    Token_type   string
    Access_token string
}

type Client Uses

type Client struct {

    // Twitter's 'statuses' function group
    Tweets *TweetsService

    // Direct Messages function group
    DM  *DMService

    // Twitter's Help function group
    Help *HelpService

    // Account functiona group
    Account *AccountService

    // Search functionality group
    Search *SearchService

    // User services
    User *UserService

    // List services
    Lists *ListService

    // Friend services
    Friends *FriendsService

    // Followers services
    Followers *FollowersService

    // API base endpoint. This is the base endpoing URL for API calls. This
    // can be overwritten by an application that needs to use a different
    // version of the library or maybe a mock.
    Endpoint string

    // The token for twitter application we are using. If it is set to "" then
    // client will assume that we are not making application-only API calls and
    // are instead making calls using user authenticated APIs
    ApplicationToken string
    // contains filtered or unexported fields
}

Client: Twitter API client provides access to the various API services

func New Uses

func New(oauthClient *http.Client) (*Client, error)

Creates a new twitter client for user authenticated API calls

func NewApplicationClient Uses

func NewApplicationClient(httpClient *http.Client, bearerToken string) (*Client, error)

Creates a new twitter client for application-only API calls

func (*Client) Call Uses

func (c *Client) Call(method, endpoint string, opts *Optionals, resp interface{}) (err error)

Performs an arbitrary API call and tries to unmarshal the result into 'resp' on success. This is generally used internally by the other functions but it could be used to perform unsupported API calls.

Example usage:

var tweet Tweet
opts := NewOptionals()
opts.Add("status", "Hello, world")
err := client.Call("POST", "statuses/update_status", opts, &tweet)

is equivalent to

tweet, err := client.UpdateStatus("Hello, world", nil)

func (*Client) CallJSON Uses

func (c *Client) CallJSON(method, endpoint string, opts *Optionals) (rawJSON []byte, err error)

Performs an arbitrary API call and returns the response JSON if successful. This is generally used internally by other functions but it can also be used to perform API calls not directly supported by tweetlib.

For example

opts := NewOptionals()
opts.Add("status", "Hello, world")
rawJSON, _ := client.CallJSON("POST", "statuses/update_status", opts)
var tweet Tweet
err := json.Unmarshal(rawJSON, &tweet)

is the same as

tweet, err := client.UpdateStatus("Hello, world", nil)

type Config Uses

type Config struct {
    ConsumerKey    string
    ConsumerSecret string
    Callback       string
}

type Configuration Uses

type Configuration struct {
    CharactersReservedPerMedia int      `json:"characters_reserved_per_media"`
    MaxMediaPerUpload          int      `json:"max_media_per_upload"`
    NonUsernamePaths           []string `json:"non_username_paths"`
    PhotoSizeLimit             int      `json:"photo_size_limit"`
    PhotoSizes                 map[string]struct {
        Width  int    `json:"w"`
        Height int    `json:"h"`
        Resize string `json:"resize"`
    }   `json:"photo_sizes"`
    ShortUrlLengthHttps int `json:"short_url_length_https"`
    ShortUrlLength      int `json:"short_url_length"`
}

type Cursor Uses

type Cursor struct {
    Next        int64   `json:"next_cursor"`
    NextStr     string  `json:"next_cursor_str"`
    Previous    int64   `json:"previous_cursor"`
    PreviousStr string  `json:"previous_cursor_str"`
    IDs         []int64 `json:"ids"`
}

type DMService Uses

type DMService struct {
    *Client
}

func (*DMService) Destroy Uses

func (dm *DMService) Destroy(id int64, opts *Optionals) (message *DirectMessage, err error)

Destroys the direct message specified in the required ID parameter. The authenticating user must be the recipient of the specified direct message. See https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy

func (*DMService) Get Uses

func (dm *DMService) Get(id int64, opts *Optionals) (message *DirectMessage, err error)

Returns a single direct message, specified by an id parameter. See https://dev.twitter.com/docs/api/1.1/get/direct_messages/show

func (*DMService) List Uses

func (dm *DMService) List(opts *Optionals) (messages *DirectMessageList, err error)

Returns the 20 most recent direct messages sent to the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 incoming DMs See https://dev.twitter.com/docs/api/1.1/get/direct_messages

func (*DMService) Send Uses

func (dm *DMService) Send(screenname, text string, opts *Optionals) (message *DirectMessage, err error)

Sends a new direct message to the specified user from the authenticating user. See https://dev.twitter.com/docs/api/1.1/post/direct_messages/new

func (*DMService) Sent Uses

func (dm *DMService) Sent(opts *Optionals) (messages *DirectMessageList, err error)

Returns the 20 most recent direct messages sent by the authenticating user. Includes detailed information about the sender and recipient user. You can request up to 200 direct messages per call, up to a maximum of 800 outgoing DMs. See https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent

type DirectMessage Uses

type DirectMessage struct {
    CreatedAt           string `json:"created_at"`
    SenderScreenName    string `json:"sender_screen_name"`
    Sender              *User  `json:"sender"`
    Text                string `json:"text"`
    RecipientScreenName string `json:"recipient_screen_name"`
    Id                  string `json:"id"`
    Recipient           *User  `json:"recipient"`
    RecipientId         string `json:"recipient_id"`
    SenderId            string `json:"sender_id"`
}

Represents a direct message -- a message between two users who follow each other.

type DirectMessageList Uses

type DirectMessageList []DirectMessage

A list of direct messages

type FollowersService Uses

type FollowersService struct {
    *Client
}

func (*FollowersService) IDs Uses

func (ls *FollowersService) IDs(screenName string, userID int64, cursor int64, opts *Optionals) (IDs *Cursor, err error)

IDs returns a cursored collection of user IDs. See https://dev.twitter.com/docs/api/1.1/get/followers/ids

type FriendsService Uses

type FriendsService struct {
    *Client
}

func (*FriendsService) IDs Uses

func (ls *FriendsService) IDs(screenName string, userID int64, cursor int64, opts *Optionals) (IDs *Cursor, err error)

IDs returns a cursored collection of user IDs. See https://dev.twitter.com/docs/api/1.1/get/friends/ids

type HelpService Uses

type HelpService struct {
    *Client
}

Groups help functions

func (*HelpService) Configuration Uses

func (hs *HelpService) Configuration() (configuration *Configuration, err error)

Returns the current configuration used by Twitter including twitter.com slugs which are not usernames, maximum photo resolutions, and t.co URL lengths. See https://dev.twitter.com/docs/api/1.1/get/help/configuration

func (*HelpService) Limits Uses

func (hs *HelpService) Limits() (limits *Limits, err error)

Returns current Twitter's rate limits See https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status

func (*HelpService) PrivacyPolicy Uses

func (hs *HelpService) PrivacyPolicy() (privacyPolicy string, err error)

Returns Twitter's Privacy Policy Seehttps://dev.twitter.com/docs/api/1.1/get/help/privacy

func (*HelpService) Tos Uses

func (hs *HelpService) Tos() (string, error)

Returns Twitter's terms of service See https://dev.twitter.com/docs/api/1.1/get/help/tos

type LimitResourceFamily Uses

type LimitResourceFamily map[string]struct {
    Remaining int   `json:"remaining"`
    Reset     int64 `json:"reset"`
    Limit     int   `json:"limit"`
}

type LimitStatus Uses

type LimitStatus struct {
    RemainingHits      int    `json:"remaining_hits"`
    ResetTimeInSeconds int    `json:"reset_time_in_secods"`
    HourlyLimit        int    `json:"hourly_limit"`
    ResetTime          string `json:"reset_time"`
    Photos             struct {
        RemainingHits      int    `json:"remaining_hits"`
        ResetTimeInSeconds int    `json:"reset_time_in_secods"`
        ResetTime          string `json:"reset_time"`
        DailyLimit         int    `json:"daily_limit"`
    }   `json:"photos"`
}

type Limits Uses

type Limits struct {
    // For which context these limits are
    // For tweetlib this will always be the user token
    Context struct {
        AccessToken string `json:"access_token"`
    }   `json:"rate_limit_context"`

    // Resrouce families are "accounts", "help", etc
    ResourceFamilies map[string]map[string]struct {
        // How many calls remaining for this resource
        Remaining int `json:"remaining"`
        // When the limit will reset (epoch time)
        Reset int64 `json:"reset"`
        // Total number of calls allowed
        Limit int `json:"limit"`
    }   `json:"resources"`
}

Represents Twitter's current resource limits See https://dev.twitter.com/docs/rate-limiting/1.1/limits Usage:

limits, _ := c.Help.Limits()
fmt.Printf("App has %d user_timeline calls remaining\n",
	limits["statuses"]["/statuses/user_timeline"].Remaining)

type List Uses

type List struct {
    User            *User  `json:"user"`
    Name            string `json:"name"`
    Slug            string `json:"slug"`
    Mode            string `json:"mode"`
    IdStr           string `json:"id_str"`
    Uri             string `json:"uri"`
    Id              int    `json:"id"`
    MemberCount     int    `json:"member_count"`
    Following       bool   `json:"following"`
    FullName        string `json:"full_name"`
    SubscriberCount int    `json:"subscriber_count"`
    Description     string `json:"description"`
}

type ListList Uses

type ListList []List

type ListService Uses

type ListService struct {
    *Client
}

func (*ListService) GetAll Uses

func (ls *ListService) GetAll(screenName string, opts *Optionals) (lists *ListList, err error)

Returns all lists the authenticating or specified user subscribes to, including their own. See https://dev.twitter.com/docs/api/1.1/get/lists/list

type Optionals Uses

type Optionals struct {
    Values url.Values
}

Optionals: used to provide optional arguments to API calls

Usage:

opts := NewOptionals()
opts.Add("count", 10)
opts.Add("lat", -37.102013)
opts.Add("user_id", "twitteruser")

func NewOptionals Uses

func NewOptionals() *Optionals

NewOptionals returns a new instance of Optionals

func (*Optionals) Add Uses

func (o *Optionals) Add(name string, value interface{})

Add: adds a new optional parameter to be used in an API request. The value needs to be "stringified"

type SearchMetadata Uses

type SearchMetadata struct {
    MaxId       int64   `json:"max_id"`
    SinceId     int64   `json:"since_id"`
    RefreshUrl  string  `json:"refresh_url"`
    NextResults string  `json:"next_results"`
    Count       int     `json:"count"`
    CompletedIn float64 `json:"completed_in"`
    SinceIdStr  string  `json:"since_id_str"`
    Query       string  `json:"query"`
    MaxIdStr    string  `json:"max_id_str"`
}

When searching, Twitter returns this metadata along with results

type SearchResults Uses

type SearchResults struct {
    // Tweets matching the search query
    Results TweetList `json:"statuses"`
    // Search metadata
    Metadata SearchMetadata `json:"search_metadata"`
}

Results of a search for tweets.

type SearchService Uses

type SearchService struct {
    *Client
}

Groups search functionality

func (*SearchService) Tweets Uses

func (sg *SearchService) Tweets(q string, opts *Optionals) (searchResults *SearchResults, err error)

Returns a collection of relevant Tweets matching a specified query. See https://dev.twitter.com/docs/api/1.1/get/search/tweets and also https://dev.twitter.com/docs/using-search

type TempToken Uses

type TempToken struct {
    Token  string
    Secret string
}

func (*TempToken) AuthURL Uses

func (tt *TempToken) AuthURL() string

type Token Uses

type Token struct {
    OAuthSecret string
    OAuthToken  string
}

type Transport Uses

type Transport struct {
    *Config
    *Token

    // Transport is the HTTP transport to use when making requests.
    // It will default to http.DefaultTransport if nil.
    // (It should never be an oauth.Transport.)
    Transport http.RoundTripper
}

func (*Transport) AccessToken Uses

func (t *Transport) AccessToken(tempToken *TempToken, oauthVerifier string) (*Token, error)

func (*Transport) Client Uses

func (t *Transport) Client() *http.Client

Client returns an *http.Client that makes OAuth-authenticated requests.

func (*Transport) RoundTrip Uses

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

func (*Transport) TempToken Uses

func (t *Transport) TempToken() (*TempToken, error)

type TrendLocation Uses

type TrendLocation struct {
    Woeid       int64  `json:"woeid"`
    Name        string `json:"name"`
    CountryCode string `json:"countryCode"`
    Country     string `json:"country"`
    Url         string `json:"url"`
    PlaceType   struct {
        Code int64  `json:"code"`
        Name string `json:"name"`
    }   `json:"placeType"`
}

type TrendLocationList Uses

type TrendLocationList []TrendLocation

type Tweet Uses

type Tweet struct {
    Contributors        string `json:"contributors"`
    User                *User  `json:"user"`
    Truncated           bool   `json:"truncated"`
    Text                string `json:"text"`
    InReplyToScreenName string `json:"in_reply_to_screen_name"`
    RetweetCount        int64  `json:"retweet_count"`
    Entities            struct {
        Urls []struct {
            DisplayUrl  string  `json:"display_url"`
            Indices     []int64 `json:"indices"`
            Url         string  `json:"url"`
            ExpandedUrl string  `json:"expanded_url"`
        }   `json:"urls"`
        Hashtags []struct {
            Text    string  `json:"text"`
            Indices []int64 `json:"indices"`
        }   `json:"hashtags"`
        UserMentions []struct {
            ScreenName string  `json:"screen_name"`
            Name       string  `json:"name"`
            Indices    []int64 `json:"indices"`
            IdStr      string  `json:"id_str"`
            Id         int64   `json:"id"`
        }   `json:"user_mentions"`
    }   `json:"entities"`
    Geo                  string `json:"geo"`
    InReplyToUserId      int64  `json:"in_reply_to_user_id"`
    IdStr                string `json:"id_str"`
    CreatedAt            string `json:"created_at"`
    Source               string `json:"source"`
    Id                   int64  `json:"id"`
    InReplyToStatusId    string `json:"in_reply_to_status_id"`
    PossiblySensitive    bool   `json:"possibly_sensitive"`
    Retweeted            bool   `json:"retweeted"`
    InReplyToUserIdStr   string `json:"in_reply_to_user_id_str"`
    Coordinates          string `json:"coordinates"`
    Favorited            bool   `json:"favorited"`
    Place                string `json:"place"`
    InReplyToStatusIdStr string `json:"in_reply_to_status_id_str"`
}

Holds a single tweet. Depending on the API call used, this struct may or may not be fully populated.

type TweetList Uses

type TweetList []Tweet

A list of tweets

type TweetMedia Uses

type TweetMedia struct {
    Filename string // Name for the file (e.g. image.png)
    Data     []byte // Raw file data
}

A media attached to a tweet. In practice, this represents an image file.

type TweetSearchMetadata Uses

type TweetSearchMetadata struct {
    MaxId       int64   `json:"max_id"`
    SinceId     int64   `json:"since_id"`
    RefreshUrl  string  `json:"refresh_url"`
    NextResults string  `json:"next_results"`
    Count       int     `json:"count"`
    CompletedIn float64 `json:"completed_in"`
    SinceIdStr  string  `json:"since_id_str"`
    Query       string  `json:"query"`
    MaxIdStr    string  `json:"max_id_str"`
}

When searching, Twitter returns this metadata along with results

type TweetSearchResults Uses

type TweetSearchResults struct {
    // Tweets matching the search query
    Results TweetList `json:"statuses"`
    // Search metadata
    Metadata TweetSearchMetadata `json:"search_metadata"`
}

Results of a search for tweets.

type TweetsService Uses

type TweetsService struct {
    *Client
}

func (*TweetsService) Destroy Uses

func (tg *TweetsService) Destroy(id int64, opts *Optionals) (tweet *Tweet, err error)

Destroys the status specified by the required ID parameter. The authenticating user must be the author of the specified status. returns the destroyed tweet if successful

func (*TweetsService) Get Uses

func (tg *TweetsService) Get(id int64, opts *Optionals) (tweet *Tweet, err error)

Returns a single Tweet, specified by the id parameter. The Tweet's author will also be embedded within the tweet.

func (*TweetsService) HomeTimeline Uses

func (tg *TweetsService) HomeTimeline(opts *Optionals) (tweets *TweetList, err error)

Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow. See https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline

func (*TweetsService) Mentions Uses

func (tg *TweetsService) Mentions(opts *Optionals) (tweets *TweetList, err error)

Returns the 20 (by default) most recent tweets containing a users's @screen_name for the authenticating user. THis method can only return up to 800 tweets (via the "count" optional parameter. See https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline

func (*TweetsService) Retweet Uses

func (tg *TweetsService) Retweet(id int64, opts *Optionals) (tweet *Tweet, err error)

Retweets a tweet. Returns the original tweet with retweet details embedded.

func (*TweetsService) Retweets Uses

func (tg *TweetsService) Retweets(id int64, opts *Optionals) (tweets *TweetList, err error)

Returns up to 100 of the first retweets of a given tweet Id

func (*TweetsService) RetweetsOfMe Uses

func (tg *TweetsService) RetweetsOfMe(opts *Optionals) (tweets *TweetList, err error)

Returns a collection of the most recent tweets authored by the authenticating user that have been retweeted by others. See https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me

func (*TweetsService) Tweets Uses

func (tg *TweetsService) Tweets(q string, opts *Optionals) (searchResults *TweetSearchResults, err error)

Returns a collection of relevant Tweets matching a specified query. See https://dev.twitter.com/docs/api/1.1/get/search/tweets and also https://dev.twitter.com/docs/using-search

func (*TweetsService) Update Uses

func (tg *TweetsService) Update(status string, opts *Optionals) (tweet *Tweet, err error)

Update: posts a status update to Twitter See https://dev.twitter.com/docs/api/1.1/post/statuses/update

func (*TweetsService) UpdateWithMedia Uses

func (tg *TweetsService) UpdateWithMedia(status string, media *TweetMedia, opts *Optionals) (tweet *Tweet, err error)

Updates the authenticating user's current status and attaches media for upload. In other words, it creates a Tweet with a picture attached.

func (*TweetsService) UserTimeline Uses

func (tg *TweetsService) UserTimeline(screenname string, opts *Optionals) (tweets *TweetList, err error)

Returns a collection of the most recent Tweets posted by the user indicated by the screen_name. See https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

type TwitterError Uses

type TwitterError struct {
    Message string `json:message` // Error message
    Code    int    `json:code`    // Error code
}

TwitterError represents an error generated by the Twitter API

type TwitterErrorReply Uses

type TwitterErrorReply struct {
    Errors []TwitterError `json:errors`
}

TwitterErrorReply: contains a list of errors returned for a request to the Twitter API

func (*TwitterErrorReply) String Uses

func (ter *TwitterErrorReply) String() string

Twitter error responses can actually contain multiple errors. This function preps them for a nice display

type User Uses

type User struct {
    ScreenName                string `json:"screen_name"`
    ListedCount               int64  `json:"listed_count"`
    FollowersCount            int64  `json:"followers_count"`
    Location                  string `json:"location"`
    ProfileBackgroundImageUrl string `json:"profile_background_image_url"`
    Name                      string `json:"name"`
    Notifications             bool   `json:"notifications"`
    Protected                 bool   `json:"protected"`
    IdStr                     string `json:"id_str"`
    ProfileBackgroundColor    string `json:"profile_background_color"`
    CreatedAt                 string `json:"created_at"`
    Url                       string `json:"url"`
    TimeZone                  string `json:"time_zone"`
    Id                        int64  `json:"id"`
    Verified                  bool   `json:"verified"`
    ProfileLinkColor          string `json:"profile_link_color"`
    ProfileImageUrl           string `json:"profile_image_url"`
    Status                    *Tweet `json:"status"`
    ProfileUseBackgroundImage bool   `json:"profile_use_background_image"`
    FavouritesCount           int64  `json:"favourites_count"`
    ProfileSidebarFillColor   string `json:"profile_sidebar_fill_color"`
    UtcOffset                 int64  `json:"utc_offset"`
    IsTranslator              bool   `json:"is_translator"`
    FollowRequestSent         bool   `json:"follow_request_sent"`
    Following                 bool   `json:"following"`
    ProfileBackgroundTile     bool   `json:"profile_background_tile"`
    ShowAllInlineMedia        bool   `json:"show_all_inline_media"`
    ProfileTextColor          string `json:"profile_text_color"`
    Lang                      string `json:"lang"`
    StatusesCount             int64  `json:"statuses_count"`
    ContributorsEnabled       bool   `json:"contributors_enabled"`
    FriendsCount              int64  `json:"friends_count"`
    GeoEnabled                bool   `json:"geo_enabled"`
    Description               string `json:"description"`
    ProfileSidebarBorderColor string `json:"profile_sidebar_border_color"`
}

Represents a Twitter user. This struct is often part of a tweet. Depending on the API call used, this struct may not be fully filled. Some calls use only the Id field.

type UserList Uses

type UserList []User

A list of users

type UserService Uses

type UserService struct {
    *Client
}

func (*UserService) Lookup Uses

func (us *UserService) Lookup(screenNames []string, userIDs []int64, opts *Optionals) (users *UserList, err error)

See https://dev.twitter.com/docs/api/1.1/get/users/lookup

func (*UserService) Search Uses

func (us *UserService) Search(q string, opts *Optionals) (users *UserList, err error)

Provides a simple, relevance-based search interface to public user accounts on Twitter. Try querying by topical interest, full name, company name, location, or other criteria. Exact match searches are not supported. See https://dev.twitter.com/docs/api/1.1/get/users/search

func (*UserService) Show Uses

func (us *UserService) Show(screenName string, opts *Optionals) (user *User, err error)

See https://dev.twitter.com/docs/api/1.1/get/users/show

Package tweetlib imports 17 packages (graph) and is imported by 1 packages. Updated 2016-07-15. Refresh now. Tools for package owners.