Skip to content

Latest commit

 

History

History
226 lines (156 loc) · 8.48 KB

README.md

File metadata and controls

226 lines (156 loc) · 8.48 KB

twitter_intent

The twitter_intent package helps you build Twitter Web Intents (URLs) and provides an idiomatic Dart interface to ask your users to

  • create tweets with custom hashtags, URL, pre-populated text, emoji-support, mentions, or replies 🐦
  • send direct messages to a user (with optional pre-populated message) 💌
  • like tweets 💙
  • follow a user 🤩
  • retweet tweets 📢

Continuous Integration codecov twitter_intent Published by dartside.dev GitHub Stars Count

Important links

If you enjoy using this package, a thumbs-up on pub.dev would be highly appreciated! 👍💙

About Twitter Web Intents

To document this package, I sometimes directly quoted from the official docs.

Introduction

Web Intents are the simplest way to let people tweet or follow Twitter accounts (amongst others).

This package helps you build Twitter Web Intents.

Web Intents let you work with tweets and Twitter users. They make is possible for users to interact with Twitter content in the context of your site/app, without having to authorize a new app just for the interaction.

Web intents are mobile friendly, include native app handlers on iOS and Android when the Twitter app is installed. This mean that if the user has the Twitter app installed, the web intents will be automatically opened in the Twitter app (instead of opening the browser).

If the user is not logged it, they will be asked to login. After login your intent will be shown to them.

Launching web intents will not actually perform any action on the user's behalf, it just makes the action easier for the user (for example, by pre-populating the tweet and adding hashtags). The package will not do anything without the user's consent.

Dart

The package works everywhere and doesn't have any Flutter specific dependency.

It works in HTML pages, regardless if you use the package on the frontend with AngularDart, "vanilla" Dart, or rendered to an a tag from your Dart HTTP server.

It would also work with markdown, as you can see in the examples below.

Flutter

If you want to use this package with Flutter, use the url_launcher plugin for launching the links that you create with the twitter_intent package.

import 'package:twitter_intent/twitter_intent.dart';

// For Flutter applications, you'll most likely want to use
// the url_launcher package.
import 'package:url_launcher/url_launcher.dart';

// ...somewhere in your Flutter app...
launchTwitterIntent() async {
  final intent = FollowUserIntent(username: 'vincevargadev');
  // Convert the intent instance to a string.
  // Use either Dart's string interpolation or the toString() method.
  // The "launch" method is part of "url_launcher".
  await launch('$intent');
}

Usage

Here are a couple of examples how you can use this package.

Don't forget to convert the intents toString to get the URLs.

I left actual, working links below each example, so that you can try them out right from your browser.

These links will also help with understanding how the web intents work on mobile, especially if the official Twitter app is installed on your phone. You can try out these intents without having to write a Flutter app just by using the links below.

Follow user

Launching a FollowUserIntent will ask to follow the specified user.

FollowUserIntent(username: 'vincevargadev');

Follow me @vincevargadev

Keep in mind that usernames might change.

Retweet

To let the user retweet a link, just look up the tweet ID and you are ready to go!

RetweetIntent(tweetId: '1355115682170597377');

Retweet my tweet about the Flutter 101 Podcast

Simple tweet intent

With the TweetIntent, you can pre-populate the user's tweet with hashtags, URLs, and the text. The user can still edit the tweet before sending it, or the user might even just cancel the tweet.

TweetIntent(
  hashtags: ['Dart', 'Flutter'],
  text: 'The new twitter_intent package is here! 🚀',
  via: 'vincevargadev',
  url: 'https://pub.dev/packages/tweet_intent',
  related: [
    RelatedAccount(
      username: 'flutter101podcast',
      description: 'Flutter Podcast',
    ),
  ],
)

Help this package get more users by tweeting about it!

Tweet intent in reply to an existing tweet

TweetIntent(
  text: 'Can\'t wait for this @FlutterDev podcast!',
  hashtags: ['Flutter', 'Dart'],
  via: 'vincevargadev',
  inReplyTo: '1355115682170597377',
);

Respond to my podcast tweet

Like tweet

LikeTweetIntent(tweetId: '1355115682170597377');

Like my podcast tweet

Direct message

// Twitter expects a user ID for DMs.
final vincevargadev = '1104126419557335042';
DirectMessageIntent(recipientId: vincevargadev);

Send me a direct message

Direct message with pre-populated text (and emojis)

// Twitter expects a user ID for direct messages.
final vincevargadev = '1104126419557335042';
DirectMessageIntent(
  recipientId: vincevargadev,
  text: 'I just tried your Twitter package and it is 👌❤️.',
);

Send me a direct message about this package

Localization

All intents in this package accept the language parameter that lets you override the language display of a logged-in user or languages accepted by the browser.

Examples: en, de, es, hu, zh-cn, ur, vi, hi, ja.

This basically means that you can set the language of the Twitter UI by passing in the language parameter.

Twitter supports 30+ languages. For the full list visit Twitter's supported languages document.

This feature only works in web browsers. Overriding the mobile app's language is not possible. If you want to test the examples below, copy the link address and open it in an incognito window.

Follow (Chinese)

FollowUserIntent(
  username: 'vincevargadev',
  language: 'zh-cn',
);

Follow me with the Twitter UI set to Chinese!

Direct message (German)

DirectMessageIntent(
  recipientId: vincevargadev,
  text: 'Hallo Vince, wie geht\'s dir? 🇩🇪',
  language: 'de',
);

German message with German Twitter UI