Giter Site home page Giter Site logo

sivchari / gotwtr Goto Github PK

View Code? Open in Web Editor NEW
78.0 6.0 13.0 257 KB

gotwtr provides Twitter v2 API

Home Page: https://developer.twitter.com/en/docs/twitter-api/tools-and-libraries/v2

License: MIT License

Go 100.00%
go golang twitter twitter-api twitter-client

gotwtr's Introduction

gotwtr

Go Reference reviewdog test

gotwtr is a Go client library for the Twitter v2 API.

Note

We covers only Twitter v2 API supported by OAuth 2.0 Bearer Token.

We will had worked on it, when new one is be handled OAuth 2.0.

Installation

go get github.com/sivchari/gotwtr

Documentation

Please see GoDoc

Example

Tweet lookup

package main

import (
	"context"
	"fmt"

	"github.com/sivchari/gotwtr"
)

func main() {
	client := gotwtr.New("YOUR_TWITTER_BEARER_TOKEN")
	// look up multiple tweets
	ts, err := client.RetrieveMultipleTweets(context.Background(), []string{"id", "id2"})
	if err != nil {
		panic(err)
	}
	for _, t := range ts.Tweets {
		fmt.Println(t)
	}

	// look up single tweet
	t, err := client.RetrieveSingleTweet(context.Background(), "id")
	if err != nil {
		panic(err)
	}
	fmt.Println(t.Tweet)
}

If you wanna more example, please see examples dir.

These are covered all code gotwtr provides Twitter v2 API interface.

Contributing

We are welcome to contribute to this project.

Fork and make a Pull Request, or create an Issue if you see any problem or any enhancement, feature request.

gotwtr's People

Contributors

akira0000k avatar github-actions[bot] avatar kazdevl avatar mecko avatar mmmommm avatar peaceiris avatar senk8 avatar sivchari avatar thinca avatar zandwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gotwtr's Issues

Goal

progress

Tweet

  • Tweet lookup
    • Retrieve multiple Tweets with a list of IDs
    • Retrieve a single Tweet with an ID
  • Manage Tweets
    • Post a Tweet (OAuth 1.0a User Context)
    • Delete a Tweet (OAuth 1.0a User Context)
  • #10
    • Returns most recent Tweets composed a specified user ID
    • Returns most recent Tweets mentioning a specified user ID
  • #11
    • Search for Tweets published in the last 7 days
    • Search the full archive of Tweets (Academic Research product track)
  • #14
    • Receive a count of Tweets that match a query in the last 7 days
    • Receive a count of Tweets that match a query (Academic Research product track)
  • #29
    • Add or delete rules from your stream
    • Retrieve your stream's rules
    • Connect to the stream
  • #30
  • #39
    • Retweets lookup
    • Allows a user ID to Retweet a Tweet (OAuth 1.0a User Context)
    • Allows a user ID to undo a Retweet (OAuth 1.0a User Context)
  • Likes
    • #31
    • #79
    • Allows a user ID to like a Tweet (OAuth 1.0a User Context)
    • Allows a user ID to unlike a Tweet (OAuth 1.0a User Context)
  • #32 (OAuth 1.0a User Context)

Lists

  • #67
    • Lookup a specific list by ID
    • Lookup a user's owned List
  • Manage List
    • Creates a new List on behalf of an authenticated user (OAuth 1.0a User Context)
    • Deletes a List the authenticated user owns (OAuth 1.0a User Context)
    • Updates the metadata a List the authenticated user owns (OAuth 1.0a User Context)
  • #66
    • Lookup Tweets from a specified List
  • List members
    • #83
    • #81
    • Add a member to a List that the authenticated user owns (OAuth 1.0a User Context)
    • Removes a member from a List the authenticated user owns (OAuth 1.0a User Context)
  • List follows
    • #75
    • #76
    • Follows a List on behalf of an authenticated user (OAuth 1.0a User Context)
    • Unfollows a List on behalf of an authenticated user (OAuth 1.0a User Context)
  • Pinned Lists
    • Returns the pinned Lists of the authenticated user (OAuth 1.0a User Context)
    • Pins a List on behalf of an authenticated user (OAuth 1.0a User Context)
    • Unpins a List on behalf of an authenticated user (OAuth 1.0a User Context)

Users

  • #53
    • Retrieve multiple users with IDs
    • Retrieve a single user with an ID
    • Retrieve multiple users with usernames
    • Retrieve a single user with a username
  • #54
    • Lookup following of a user by ID
    • Lookup followers of a user by ID
    • Allows a user ID to follow another user (OAuth 1.0a User Context)
    • Allows a user ID to unfollow another user (OAuth 1.0a User Context)
  • #55
    • Returns a list of users who are blocked by the specified user ID (OAuth 1.0a User Context)
    • Allows a user ID to block another user (OAuth 1.0a User Context)
    • Allows a user ID to unblock another user (OAuth 1.0a User Context)
  • #56
    • Returns a list of users who are muted by the specified user ID (OAuth 1.0a User Context)
    • Allows a user ID to mute another user (OAuth 1.0a User Context)
    • Allows a user ID to unmute another user (OAuth 1.0a User Context)

Spaces

  • #45
    • Lookup Space by ID
    • Lookup multiple Spaces by ID
    • Get users who purchased a ticket to a Space
    • #62
  • #40

Add test

#12

This code isn't written test code.
So, we must write it.

v1.1 Goal

progress

OAuth

  • Generate Bearer Token

Tweet

  • Manage Tweets
    • Post a Tweet
    • Delete a Tweet
  • Search Tweets
    • Search the full archive of Tweets (Academic Research product track)
  • Tweet Counts
    • Receive a count of Tweets that match a query (Academic Research product track)
  • Retweets
    • Allows a user ID to Retweet a Tweet
    • Allows a user ID to undo a Retweet
  • Likes
    • Allows a user ID to like a Tweet
    • Allows a user ID to unlike a Tweet
  • #143

Lists

  • Manage List
    • Creates a new List on behalf of an authenticated user
    • Deletes a List the authenticated user owns
    • Updates the metadata a List the authenticated user owns
  • List members
    • Add a member to a List that the authenticated user owns
    • Removes a member from a List the authenticated user owns
  • #133
    • Follows a List on behalf of an authenticated user
    • Unfollows a List on behalf of an authenticated user
  • #134
    • Returns the pinned Lists of the authenticated user
    • Pins a List on behalf of an authenticated user
    • Unpins a List on behalf of an authenticated user

Users

  • Follows
    • Allows a user ID to follow another user
    • Allows a user ID to unfollow another user
  • Blocks
    • Returns a list of users who are blocked by the specified user ID
    • Allows a user ID to block another user
    • Allows a user ID to unblock another user
  • Mutes
    • Returns a list of users who are muted by the specified user ID
    • Allows a user ID to mute another user
    • Allows a user ID to unmute another user

Batch compliance

Bookmarks

  • Allows you to get information about a authenticated user’s 800 most recent bookmarked Tweets.
  • Causes the user ID of an authenticated user identified in the path parameter to Bookmark the target Tweet provided in the request body.
  • Allows a user or authenticated user ID to remove a Bookmark of a Tweet.

Should we implement covid19-stream ?

Twitter provides new API covid19-stream. I'm annoying to should implement these. This API may be deprecated in the future (I hope it). As a result, If library user use these API, the user library isn't working. Of cource we can keep these API , but I worry about if it's good way. What do you think ?

Modify what to do when an error is kind of rate-limit occurs

It relates

TODO: must consider way of processing APIError such as kind of late limit
{
name: "429 - Too Many Requests",
args: args{
ctx: context.Background(),
client: mockHTTPClient(func(request *http.Request) *http.Response {
body := `{ "title": "ConnectionException", "detail": "This stream is currently at the maximum allowed connection limit.", "connection_issue": "TooManyConnections","type": "https://api.twitter.com/2/problems/streaming-connection"}`
return &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: io.NopCloser(strings.NewReader(body)),
}
}),
opt: []*gotwtr.ConnectToStreamOption{},
},
want: &gotwtr.ConnectToStreamResponse{
Error: &gotwtr.APIResponseError{
Title: "ConnectionException",
Detail: "This stream is currently at the maximum allowed connection limit.",
ConnectionIssue: "TooManyConnections",
Type: "https://api.twitter.com/2/problems/streaming-connection",
},
},
wantErr: true,
},
*/
.

At https://github.com/sivchari/gotwtr/blob/main/filtered_stream.go#L131-L138, we return HTTPError instead of APIResponseError through channel. This may be an issue if we want to check the cause of the error, so we need to consider modifying it.

Note

  • This issue occurs when an error is kind of rate-limit happens. (e.g. 429 Too many requests)

improve test

Now, all unit tests codes mock response as string. Go provides embed feature, so we should replace all mock response to json file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.