Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Switch to the v2 Twitter API #207

Merged
merged 13 commits into from
Oct 6, 2022
Merged

feat: Switch to the v2 Twitter API #207

merged 13 commits into from
Oct 6, 2022

Conversation

MattIPv4
Copy link
Member

@MattIPv4 MattIPv4 commented Sep 23, 2022

breaking change: Moves to using the v2 API. Twitter apps need to be in a project to access the v2 API.

breaking change: When retweeting, the only URL returned now is the original tweet, not the retweeter's tweet.

Replaces the twitter library with twitter-api-v2, and switches the logic over to using the v2 Twitter API where possible.

This removes the need for the Ads API as the v2 tweet endpoint supports polls directly. This still uses the v1 API for media, but essentials API access will allow access to this as there is no v2 equivalent currently.

// }

return id;
const mediaId = await client.v1.uploadMedia(file, { mimeType: mime.lookup(file) });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that the v2 API does not support media uploads?

Will twitter accounts without v1 access be unable to upload media?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I note in the description above:

This still uses the v1 API for media, but essentials API access will allow access to this as there is no v2 equivalent currently

@MattIPv4 MattIPv4 changed the title Switch to the v2 Twitter API feat: Switch to the v2 Twitter API Sep 24, 2022
@MattIPv4
Copy link
Member Author

Only remaining work here now is to update the README and docs directory to remove references to the Ads API, to remove guidance on requesting elevated access as only essentials access is required now (v2 + v1 media), and to remove the comment that alt text cannot be set as it now can be.

@IstoraMandiri
Copy link
Contributor

IstoraMandiri commented Oct 2, 2022

I have tested each tweet type's pull request flow in production over at https://github.com/IstoraMandiri/twitter-together-testing.

The twitter account only has v2 API access, but required setting up read/write permissions in a way that is different to the current docs. This should be updated.

I was able to confirm that this branch seems to be working as expected other than some PR preview bugs and misc improvements, for which I have added issues in this repo.

@MattIPv4 MattIPv4 force-pushed the MattIPv4/twitter-v2-api branch from 5cd0ee0 to 184845c Compare October 3, 2022 15:25
@MattIPv4 MattIPv4 marked this pull request as ready for review October 3, 2022 16:05
@MattIPv4 MattIPv4 requested a review from gr2m October 3, 2022 16:05
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work!!

One more thing we need to change is the release.yml workflow here:

HEAD:refs/heads/v2

This won't be necessary once I get to work on #205 😢

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 3, 2022

Should I bump package.json to 3.0.0 at the same time, or should I leave that for the bot to handle still?

@gr2m
Copy link
Contributor

gr2m commented Oct 3, 2022

Should I bump package.json to 3.0.0 at the same time, or should I leave that for the bot to handle still?

that should be done by semantic-release via this configuration:

action/package.json

Lines 60 to 67 in dffa59c

"@semantic-release/git",
{
"assets": [
"package.json",
"dist/index.js"
],
"message": "build(release): compiled action for ${nextRelease.version}\n\n[skip ci]"
}

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 3, 2022

Cool, will bump the workflow, pls hold

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀:shipit:

@IstoraMandiri
Copy link
Contributor

Nice, can confirm the Twitter App creation docs are also looking very good and match my recent experience.

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 5, 2022

@gr2m Is there anything blocking merging this? Wasn't sure if I can boop the button, or if you'd left it unmerged for a reason?

@gr2m
Copy link
Contributor

gr2m commented Oct 6, 2022

Wasn't sure if I can boop the button, or if you'd left it unmerged for a reason?

Usually I leave it up to the author to merge the pull request at their convenience, especially for more complex pull requests. So yeah, when things are green, boop away at your pleasure

@MattIPv4 MattIPv4 merged commit f6851e3 into main Oct 6, 2022
@MattIPv4 MattIPv4 deleted the MattIPv4/twitter-v2-api branch October 6, 2022 18:17
@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 6, 2022

🚀 booped

@MattIPv4 MattIPv4 mentioned this pull request Oct 6, 2022
@gr2m
Copy link
Contributor

gr2m commented Oct 6, 2022

🎉 This PR is included in version 2.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@gr2m gr2m added the released label Oct 6, 2022
@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 6, 2022

:sus: Why did it release it as minor

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 6, 2022

Gregor, can you do some magic to unrelease that minor release, 'cause this is very likely a breaking change for some folks 🤔

@IstoraMandiri
Copy link
Contributor

Pretty sure @MattIPv4 is right, @gr2m, as presumably current v1 API users would need to set up new keys to use the v2 endpoints?

I cannot easily test this unfortunately.

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 7, 2022

Most users should be safe, it's only breaking for those that're using apps outside a project, as legacy apps only have v1 access. (I think, I also could be totally wrong there)

I'm guessing the bot didn't look at the PR body, only the commit body (which just had the normal commit log w/o the breaking change warnings). Automation 😓

@IstoraMandiri
Copy link
Contributor

IstoraMandiri commented Oct 7, 2022

I notice that the dist build is not lined up with the release's semver.

/***/ 4147:
/***/ ((module) => {

"use strict";
module.exports = {"i8":"2.1.2"};

Perhaps bump the package.json to 3.0.0 and rebuild?

@gr2m
Copy link
Contributor

gr2m commented Oct 7, 2022

:sus: Why did it release it as minor

Ouch, sorry :(

semantic-release needs a BREAKING CHANGE: ... in the commit body in order to do a breaking release.
I've documented the conventions here: https://github.com/twitter-together/action/blob/main/CONTRIBUTING.md#merging-the-pull-request--releasing-a-new-version

As we don't release to npm, we can just delete the git tag/github release and have semantic-release do a breaking release with an empty commit. I'm on it

@gr2m
Copy link
Contributor

gr2m commented Oct 7, 2022

🎉 This PR is included in version 2.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@gr2m
Copy link
Contributor

gr2m commented Oct 7, 2022

the above comment makes no sense to me 🤷🏼

Here are the two relevant releases

2.x maintenance releases can be done with pull requsets against the 2.x branch

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 8, 2022

Ty for the fix -- yah, figured it was probably the lack of breaking change mention in the commit. I'd read the doc before but I think parsed it as needing breaking change in the PR body, not commit body (though commit makes far, far more sense).

@gr2m
Copy link
Contributor

gr2m commented Oct 8, 2022

semantic-release only works on git. The interaction with GitHub is just a plugin. Hence the need to have correct commit messages. I'd love a better integration with GitHub using an app for a long time now. The day just need more hours 🤣

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 8, 2022

Makes total sense, I just had a lapse in brain function 😂

@MattIPv4
Copy link
Member Author

MattIPv4 commented Oct 8, 2022

To Istora's point above though, https://github.com/twitter-together/action/blob/v3/dist/index.js does declare itself as v2 still though 'cause it was built before the package.json bump was done.

Is there a semantic-release plugin that can run the build command after the version bump, and then commit both the updated package.json and dist.js? (Which I think is really all that's needed to solve for #205)

@gr2m
Copy link
Contributor

gr2m commented Oct 8, 2022

I think this can be done via https://github.com/semantic-release/git

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants