go-twitter
go-twitter copied to clipboard
Add in functionality to upload media to twitter
This wraps the media upload and upload status checking API calls so clients can upload media to twitter.
And apparently this contains the Config fetch patch too, since branching is hard. (D'oh!) I can sort them both out into properly separate patches if you're not sure you want the config patch.
Great work!
It would be nice if the init, append, and finalize calls were separated. This current implementation is a good MVP, but I'd also like to see concurrency and block retrying. If that's too much to add to the library, splitting those calls up would allow users to implement those things themselves.
The first pass of the API I trued while I was working this out did have the calls surfaced individually, but when I was using it in my app I realized it didn't bring me any advantages and was just annoying to use. (Surfacing the calls while still providing a bundled API was both messy and required a lot of boilerplate testing that didn't seem to bring any value) Bundling everything together was just a lot easier to use, and I figured anyone who really wanted more low-level control was probably just calling the twitter API themselves.
The code also doesn't retry blocks and dies on first failure intentionally -- my assumption there was that this was server-side (or at least running on a permanently connected machine) code, so the vast majority of failure cases would involve just redoing everything and there wasn't much value in retries. I'm not averse to adding some retry logic, though.
As far as concurrency goes, are you talking about sending different blocks of the same file in parallel? Or some other form of concurrency? (The twitter API doesn't mention that parallel block uploads is allowable, and since the API is rate-limited it seems a good way to run into quota issues)
@drswork Ok, thanks, I see your reasoning here. Most of the statements in the docs about retrying refer to flaky cell networks. I am in an OS class right now so I've got parallelization on the brain, but I didn't think about rate limiting.
Above all else I'd love to see this PR merged so it can start being used and iterated on if need be.
Is there any progress here? I would love to have this feature in my project using this library. Do you need help to get this ready to merge? Would like to help to finish this feature.
I'm not aware of any outstanding issues. (I've had a twitter bot running since the summer using this so at least the code works OK in the basic, or at least my, case) I think it's mostly that I sent it in when dghubble turned his attention to other things so it's kinda sitting.
But what if it merged and we improve this afterwards?
EDIT: Need the approval from @dghubble
Yep, @dghubble needs to give his OK. I'm good reworking the code if necessary, that's probably not a big deal.
Hey @dghubble could you please check in this feature please :). It would be really nice to have it :)
Hi,
Hope you are all well !
Is it possible to add media to a tweet with your pull request ?
Cheers, X
@x0rzkov are you asking if with this patch can you send tweets with images attached? Yep, you can. You have to upload the image first and get its ID. Then you can send a tweet with that media ID attached. Folks will see a tweet with an image in it.
@dghubble can you merge this pull request please ? or maybe you have a specific point of view on it ?!
@drswork can you provide a quick code example of how it works ? ndlr. to attach a media to a tweet, I forked your code, and want to give a try.
Attaching an image to a tweet is pretty simple. Code looks like:
tweetParams := &twitter.StatusUpdateParams{}
if msg.OutboundImage != nil {
res, resp, err := t.Client.Media.Upload(msg.OutboundImage.Contents, msg.OutboundImage.Type)
if err != nil {
return err
}
if res.MediaID > 0 {
tweetParams.MediaIds = []int64{res.MediaID}
}
}
tweet, resp, err := t.Client.Statuses.Update(msg.OutboundStatus, tweetParams)
In this case msg is a struct internal to the server that has the status text and image contents and type in it for the tweet that needs to be sent out.
@drswork thanks, it works like a charm
@dghubble - one more vote to see this merged and released soon! 👍
One thing I would add to this is support for media_category. One thing this allows is for users to upload GIFs >= 5mb. I had to modify this library to support that.
Waiting to see this being merged!
@dghubble Thanks for your amazing library. Can I help to test this feature?
I tested it and it's working
I'm using this feature in production and works well. Simple example of usage:
media, resp, err := client.Media.Upload(content, "tweet_image")
if err != nil {
log.Fatal(err)
}
tweet, resp, err := client.Statuses.Update("your tweet comment here...", &twitter.StatusUpdateParams{
MediaIds: []int64{media.MediaID},
})
if err != nil {
log.Fatal(err)
}
Any status on this getting merged?
@dghubble what do you think about getting this merged?
@dghubble great library.... can you merge uploadMedia functionality please?
I am waiting for
I am waiting for
Any updates on this? Not having the ability to upload photos is a deal breaker for me
will be good if it's merged
Any news on merging this? It's actually a winning feature
FWIW I’m maintaining my branch (and I use the media functionality so I make sure to keep it working), so you can always use that if you need this.
Thanks @drswork, I am switching to your repo instead.