Code Monkey home page Code Monkey logo

twitter-status's Introduction

<twitter-status>

Version Status macOS Build Status Linux Build Status Windows Build Status Dependency Status npm bundle size (minified + gzip)

Twitter Status Web Component

Examples

Live demo

Base example

Example

Example with attached image

Example with image

Example with hyperlinked hashtags/mentions/URLs and links colored from profile settings.

Example with image

Install

Load directly from unpkg:

<script async src="https://unpkg.com/twitter-status@latest/dist/twitter-status.min.js"></script>

Or installed as a dependency:

npm install twitter-status

And imported:

import 'twitter-status';

Polyfill

twitter-status relies on the shadow DOM and custom elements standards. You will likely need a polyfill until browser support is more ubiquitous.

Polyfills can be loaded via unpkg directly.

<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2/bundles/webcomponents-sd-ce.js"></script>

Or installed as a dependency:

npm install @webcomponents/webcomponentsjs

And imported:

import '@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce';

Usage

<twitter-status> takes a single value status that must be the full response of GET statuses/show/:id with the parameters include_entities=true and tweet_mode=extended.

You can embed the tweet in the HTML as a JSON string:

<twitter-status status="{\"id_str\":\"20\",...}"></twitter-status>

Or set the property in JS:

<twitter-status></twitter-status>

<script>
  document.querySelector('twitter-status').status = { "id_str": "20", ... };
</script>

Theme

You can theme the borders. Here is an card example.

<style>
  twitter-status.card {
    box-shadow: 0 3px 4px 1px rgba(0, 0, 0, .08), 0 1px 1px 1px rgba(0, 0, 0, .05);
    border-radius: 2px;
    border-width: 0;
  }
</style>
<twitter-status class="card" status="{\"id_str\":\"20\",...}"></twitter-status>

Example with card edges

Reasons

Why use <twitter-status> instead of Twitter's embedded tweets?

  • Open source - If you don't like something about it you can customize it to fit your exact needs.
  • Lightweight
  • Security - You can perform a security audit of <twitter-status> and know exactly what you are shipping. You don't have to worry about loading Twitter's JavaScript.
  • Privacy - <twitter-status> only loads embedded images and videos from Twitter's CDN. You don't have to worry about loading Twitter's JavaScript.
  • Native web component - <twitter-status> is built with standardized web APIs that will work out of the box with most frameworks.
  • No framework dependancies - Because it's based on native web components, it does not have a dependency on Angular, React, or any other framework.
  • Custom URL handling (coming soon) - When a user click on a #hashtag, @mention, etc, you can configure it that they stay within your site.
  • Cached data - If you are a news organization or displaying tweets from politicians, you can continue displaying deleted tweets.
  • Well tested - <twitter-status> as a nice suit of tests to make sure everything continues to render correctly.

Limitations of <twitter-status>

  • Web component polyfills - Shadow DOM and custom elements are not supported in all browsers, if you are not already using web components the pollyfills may add additional data cost.
  • Twitter cards - Twitter fetches data about links and embeds those in tweets. The data is not available via the API so <twitter-status> does not have access.
  • Status object - <twitter-status> requires the full tweet object. If you only have an ID you'll have to make a request to the Twitter API before using the component.
  • Activity counts - Because the status objects may be stale, like, retweet, and reply counts are not displayed.
  • Open source - This project is not backed by any financing so work gets done as time permits. There are known status types that are not supported yet.

What other options are there?

<twitter-user>

Looking for a way to embed users? Check out <twitter-user>.

Notes

TwitterStatus is released under an MIT license.

TwitterStatus is not affiliated Twitter, Inc.

Built, tested, and published with Nutmeg.

twitter-status's People

Contributors

abraham avatar dandv avatar dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar wstrinz 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

twitter-status's Issues

Microsoft Edge a PITA

I just realized microsoft edge does not fully support web component hence twitter-status is not showing up. Does anyone know how to solve this? Is there a way to make web component work on Edge? I so far down the hole and really hope there's a solution to this.

Thanks in Advance.

Any plan to support APIv2 response?

<twitter-status> takes a single value status that must be the full response of GET statuses/show/:id with the parameters include_entities=true and tweet_mode=extended.

As the document says, we can't use the response of APIv2 (e.g. GET /2/tweets)
Is there any plan to support APIv2?

Example for tweet ID 20 from APIv2
{
   "data":[
      {
         "author_id":"12",
         "conversation_id":"20",
         "possibly_sensitive":false,
         "public_metrics":{
            "retweet_count":122191,
            "reply_count":10828,
            "like_count":179563,
            "quote_count":19323
         },
         "id":"20",
         "created_at":"2006-03-21T20:50:14.000Z",
         "lang":"en",
         "reply_settings":"everyone",
         "text":"just setting up my twttr",
         "source":"Twitter Web Client"
      }
   ],
   "includes":{
      "users":[
         {
            "verified":true,
            "entities":{
               "description":{
                  "hashtags":[
                     {
                        "start":0,
                        "end":8,
                        "tag":"bitcoin"
                     }
                  ]
               }
            },
            "name":"jack",
            "protected":false,
            "id":"12",
            "created_at":"2006-03-21T20:50:14.000Z",
            "pinned_tweet_id":"1247616214769086465",
            "description":"#bitcoin",
            "profile_image_url":"https://pbs.twimg.com/profile_images/1115644092329758721/AFjOr-K8_normal.jpg",
            "public_metrics":{
               "followers_count":6433546,
               "following_count":4579,
               "tweet_count":28623,
               "listed_count":32977
            },
            "url":"",
            "username":"jack"
         }
      ]
   }
}

Support native retweets

Currently it shows the retweeter name and "RT text" when it should just use the actual tweets name and text. Probably with a "retweeted by" text present.

Approach - recreating the layout vs. embedding

Thanks for making this available as a web component and not succumbing to picking a framework over another.

Would it help to document how this differs from using Twitter's oEmbed API? Seems like the component does a lot of work to replicate what others do by simply using that API and including the //platform.twitter.com/widgets.js script, and that comes with a loss of fidelity, and issues like #74. A comparison with using the embedding API would be great. Thanks!

Bloqué par une stratégie de sécurité de contenu

Bloqué par une stratégie de sécurité de contenu

Une erreur est survenue pendant une connexion à github.com.

Firefox a empêché le chargement de cette page de cette manière car sa stratégie de sécurité de contenu ne le permet pas.

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.