chimeracoder / anaconda Goto Github PK
View Code? Open in Web Editor NEWA Go client library for the Twitter 1.1 API
License: MIT License
A Go client library for the Twitter 1.1 API
License: MIT License
Hi! Getting great use out of this excellent lib. Thank you!
I need to make use of items in the RetweetedStatus (retweeted_status
) object, but in all cases where there is a retweet, it looks like this RetweetedStatus:0xc2084ed700
instead of the full Twitter object which I expect to be there. (When it is not a retweet, it is RetweetedStatus:<nil>
which is expected.)
Didn't find anyone else reporting this issue, but I can't see a way in which my own code would be causing it. Any ideas?
Thanks!
go get github.com/ChimeraCoder/anaconda
../github.com/dustin/gojson/encode.go:247: undefined: sync.Pool
accounts/verify_credentials doesnt work with 1.1, it needs to have v1 base url.
account.go https://github.com/ChimeraCoder/anaconda/blob/master/account.go
Kindly fix this.
Thanks
I'm looking for this endpoint: https://dev.twitter.com/rest/reference/get/statuses/home_timeline
GetStatusesHome_timeline
doesn't work.
Using anaconda within appengine fails as AuthorizationURL
and GetCredentials
use http.DefaultClient
. As per the documentation, appengine fetches need to use the urlfetch
package. It's possible to override the client for the API object, but this isn't used for these calls.
Either these methods should be on the API, which I think is tricky as it requires passing around the API to the callback, or the client could be passed in to the methods, which is unfortunate.
If there's another way to handle this, with the existing code or with a patch, i'd like to hear it.
I am looking to add mentions to the tweets my app users will post. From twitter API doc https://dev.twitter.com/rest/reference/post/statuses/update it seems that the is a propery called user_mentions in the tweet JSON structure. I found that, this param is missing in the tweet struct in tweet.go
How can I post mention in tweet? Should concatenating @to_user_name to the beginning of the Text
will be enough?
Looks pretty straightforward; will see about sending a PR.
https://dev.twitter.com/overview/api/entities-in-twitter-objects#extended_entities
Hi,
I have a small proc gen bot using this api and it recently started to fail on the uploads. With no code change on my side.
I still have to do full testing but I noticed that twitter specifies you should be using multipart/form-data and should be set to application/octet-stream
https://dev.twitter.com/rest/reference/post/media/upload
The OAuth lib you are using doesn't use the normal go multipart writer and sets application/x-www-form-urlencoded. I'm wondering if Twitter got a bit more strict on this.
Is this a known issue? Is anyone else getting this?
Add a way to send in_reply_to_status_id
with a tweet when posting.
See https://dev.twitter.com/rest/reference/post/statuses/update
It would be awesome. If I get the time, I'll try to do it myself.
Right now error handling is pretty basic, but a dedicated error type would help applications that want to take different actions based on the specific error received (ie, to slow down when a 'Rate limit exceeded' error is encountered, versus a 'Sorry, that page does not exist" error.
(Even when we implement rate limiting as in #1, this will still be needed because we can't be sure that the same credentials aren't being used by some other application simultaneously).
Method calls that work with the standard api.GetSearch(...)
fail with api.PublicStreamFilter(v)
, the debug output being:
2015/05/11 18:15:32 [start of for loop]
2015/05/11 18:15:32 [requesting stream]
2015/05/11 18:15:33 Twitter streaming: leaving after an irremediable error: [401 Authorization Required]
<hangs>
Simple repro below:
func main() {
flag.Parse()
anaconda.SetConsumerKey(*consumerKey)
anaconda.SetConsumerSecret(*consumerSecret)
api := anaconda.NewTwitterApi(*token, *tokenSecret)
api.SetLogger(anaconda.BasicLogger)
searchResult, err := api.GetSearch("twitter", nil)
if err != nil {
log.Fatal(err)
}
// works
for _, tweet := range searchResult.Statuses {
fmt.Println(tweet.Text)
}
v := url.Values{}
v.Set("track", "tweet")
// Fails: Twitter streaming: leaving after an irremediable error: [401 Authorization Required]
stream := api.PublicStreamFilter(v)
select {
case <-stream.Quit:
log.Println("Quitting")
case elem := <-stream.C:
fmt.Println(elem)
}
}
Hi,
I'm posting images (without uploading them) but for some reason I can never get the preview to show up. ie: https://twitter.com/martinni39/status/634554677410054144.
I believe this is on twitters part, but I'd just like to make sure.
This is the converse of friends/ids.
https://dev.twitter.com/docs/api/1.1/get/followers/ids
I would fork/pull request and make the changes but I understand there is active development atm. I would be happy to do so when the project is in a state of less flux.
When I use the demo code I get this error in the browser. But if I was to grab a single tweet everything works fine. Does anybody have a work around or is this a bug?
searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult.Statuses {
w.Header().Set("Content-Type", "Application/json;charset=UTF-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(tweet)
}
Tweets may have "quoted_status" if the retweet was quoted. Having a pointer to "quoted_status" similar to "retweeted_status" would be great.
The field "withheld_in_countries" in Twitter Json structures (WithheldInCountries
in User
) is still string
not []string
(command GetUserTimeline), current version cannot unmarshal structures because of this issue.
I tried get all friends of user but it returns only 200 of them. How can I get all of them ?
api := getNewAPI(token, tokenSecret)
v := url.Values{}
v.Set("count", "200")
v.Set("skip_status", "true")
friends := <-api.GetFriendsListAll(v)
Not sure why it was never implemented, but you can't pass url.Values to GetHomeTimeline. This makes it hard if you want to poll using "since_id".
Also why not expose apiGet/apiPost so people can extend missing api calls/options?
Hello,
azr/backoff commited a change 3 hours ago changing backoff.BackOffer
to backoff.Interface
.
Is a quick fix to be expected or should I use a vendored version of the library?
Regards,
...and also unnecessary! Thanks to the wonders of Go's channels, it should be easy to create auxiliary methods that abstract away the tedious, repeated calls to the same endpoint except with the cursor value changed.
Hello, I noticed the ApiError
has access to the response headers. However, I was wondering if there is a way to access the headers on a success response too?
On any given successful response there is also rate-limit information passed back in the headers.
https://dev.twitter.com/rest/public/rate-limiting
X-Rate-Limit-Limit: the rate limit ceiling for that given request
X-Rate-Limit-Remaining: the number of requests left for the 15 minute window
X-Rate-Limit-Reset: the remaining window before the rate limit resets in UTC epoch seconds
If this is currently not available let me know if you have thoughts on where this could fit in the library. I'd be happy to help build it in.
The GetFriendsIdsAll function is identical to the GetFriendsIds function (and consequently doesn't match the docs).
Would be great to get that added as it looks like it would be much easier to use.
I had to add:
import (
"net/url"
"github.com/ChimeraCoder/anaconda"
)
Is that correct? If so, maybe nice to mention in the readme.md.
Great lib btw :-)
anaconda.NewTwitterApi
creates channel and go routine to listen for queries, but there's no way to close this channel and make object available for gc. This is kind of annoying when you create thousands of clients.
go get github.com/ChimeraCoder/anaconda
# github.com/dustin/gojson
../src/github.com/dustin/gojson/encode.go:247: undefined: sync.Pool
anacaonda.Tweet
has a field called FavoriteCount
while anaconda.User
has a field called FavouritesCount
.
It would be nice is the library used the same spelling for both fields. For what it's worth, the twitter API seems to prefer the non-US "favourite".
The symbols entity
An array of financial symbols starting with the dollar sign extracted from the Tweet text.
It doesn't look like anaconda supports streaming API.
As of 415ee7d, the GetSearch example in the README does not compile.
This was pointed out by @tracetalbot on Twitter.
The README doesn't seem to contain any examples for streaming API. The functionality is definitely there, as can be seen in the source and comments.
Is it possible to undo retweets? Apparently it should be done using destroy api (noob in twitter API).
This was added later by @quiznilo, so it has not yet been updated to use the throttler.
What would be the "best way" to get new followers? Basically i have to follow everyone who follows me.
I know i could follow all the followers that is returned by GetFollowersList, but this doesn't seem to be a good way to do it.
Any recommendations will be appreciated.
https://dev.twitter.com/rest/reference/post/direct_messages/destroy
Can you please implement this? I did not find anything related to it in the godoc.
This comes from a suggestion from @dsymonds (golang/lint#32).
Also, the variable names should be fixed (as per the discussion).
This is for the users/report_spam API call. I needed to write a bot today to automatically report+block some users spamming me.
The returned JSON contains properties such as Display_url
instead of display_url
and Expanded_url
instead of expanded_url
.
Is there a reason for this? I see some fields do get renamed such as VideoInfo
to video_info
on line 47, but most don't.
As @sethwklein pointed out in #go-nuts, taking a pointer to url.Values would allow passing 'nil' if no optional arguments are required.
An alternative is to create a TwitterOptions struct type to handle the fact that many endpoints may have shared options, though this would make things more complicated. (Similar: http://tip.golang.org/pkg/net/#DialOpt)
Hello,
I am relatively new to Go so please forgive me if this is a noob question.
I am trying to parse the coordinates out of a tweet. Currently I have the following code:
for _, tweet := range tweets {
p := tweet.Coordinates.(map[string]interface {})
c := p["coordinates"].([]interface{})
lat := c[1].(float64)
lng := c[0].(float64)
While this works fine I am wondering if there is a more idiomatic / type safe way too do this - perhaps with a struct like this (though I have no idea how to use this struct):
type geoJSON struct {
Coordinates []float64 `json:"coordinates"`
Type string `json:"type"`
}
Hi.
I am doing a Twitter bot working on several accounts (two in my case). But when I start a goroutine and initialize Twitter API, it stops the other one.
How should I handle multiple goroutines with Anaconda for my program to work ?
Thanks !
Hello,
While making the twitter bot I realise that I should have to call two applications, e.g. use different application keys at the same time. It looks like the anaconda currently does not support it. I do not mind try to do it myself, but do you maybe have design considerations about it?
Regards,
Alex
I can authenticate w/ mrjones/oauth and store the user token/secret, but after that when trying to use anaconda for any api requests just results in the error below.
I've verified that the consumer key/secret, and user token/secret are referenced correctly, but anaconda just does not want to work for me. Am I doing something obviously wrong here?
Get https://api.twitter.com/1.1/statuses/show.json?id=634839419317456896 returned status 401, {"errors":[{"code":32,"message":"Could not authenticate you."}]}
anaconda.SetConsumerKey(os.Getenv("TWITTER_KEY"))
anaconda.SetConsumerSecret(os.Getenv("TWITTER_SECRET"))
api := anaconda.NewTwitterApi(userToken, userTokenSecret)
res, err := api.GetTweet(634839419317456896, nil)
Hi!
I'm working on a small-ish project which will require support for Twitter Lists. Figured I'd add support for them to anaconda. Is this something you'd be interested in accepting a PR for once I am done?
Why Tweet struct doesn't have a Retweeted_status struct inside such as Retweet struct? Some tweets fetched from a user timeline are truncated. It's possible to recover the full text without unmarshalling this Retweeted_struct from the response?
It should be straightforward to implement rate-limiting as https://github.com/ChimeraCoder/goangel does without changing the interface of the library.
With Go 1.4, the go generate
command was added, which allows us to tie in gojson more cleanly. (gojson is the same tool that was being used previously, just informally).
Automatically generating the struct definitions is more robust, cleaner, less error-prone, and also makes it easier for us to update the library if the API changes at any point in the future.
The unit tests should use replay
(once @kisielk writes this).
Anaconda I often use is very useful. Thank you always.
But at times I bump into "json: cannot unmarshal array into Go value of type string". Probably I think a type of Tweet.Scopes is different. Is it not map[string]string but map[string]bool?
See
https://github.com/ChimeraCoder/anaconda/blob/master/README#L83-L92
At this point, no bucket
is set.
Correct should maybe to use EnableThrottling
and DisableThrottling
?
Maybe also add a note about bufferSize
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.