npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-twitter3-connect-plugin

v1.0.5

Published

Twitter Connect Plugin - Allows single-sign on logins using Latest Twitter SDK

Downloads

5

Readme

twitter-plugin

Using Twitter Kit 3

Cordova/PhoneGap plugin to use Twitter Single Sign On

Available on npm at: https://www.npmjs.com/package/cordova-twitter3-connect-plugin

Install

Create a Twitter app

Create a Twitter application in https://apps.twitter.com and get the consumer key and secret under the "Keys and Access Tokens" tab.

IMPORTANT OR OTHERWISE LOGIN WILL FAIL: Make sure that the Callback URL contains:

twittersdk://
twitterkit-CONSUMERKEY://

See: https://developer.twitter.com/en/docs/basics/apps/guides/callback-urls.html

(replace CONSUMERKEY by your twitter app consumer key)

If desired to see the user's email (for example, by using the verify credentials endpoint), the "Additional Permissions" (in the "Permissions" tab) needs to be checked. Consequently, fill in the respective Privacy Policy URL and Terms of Service URL fields.

Add plugin to your Cordova app

Make sure you put in your valid API keys in their respective place.

cordova plugin add https://github.com/guylando/twitterkit3-plugin --variable TWITTER_KEY=<Twitter Consumer Key> --variable TWITTER_SECRET=<Twitter Consumer Secret>

IMPORTANT: This plugin has all necessary url scheme handling built-in and does not require you to add anything to your ios AppDelegate. However some plugins such as https://github.com/jeduan/cordova-plugin-facebook4 have openUrl code which prevents this plugin openUrl to run resulting in the login not finalizing after coming back to the app from the twitter webview. So if such problems are encountered then check which plugins are you using and fix the bug there. See: https://github.com/jeduan/cordova-plugin-facebook4/issues/166

Usage

This plugin adds an object to the window named TwitterConnect. The following methods are provided by the plugin.

Login

Login using the .login method:

TwitterConnect.login(
  function(result) {
    console.log('[Login] - Successful login!');
    console.log(result);
  },
  function(error) {
    console.log('[Login] - Error logging in: ' + error);
  }
);

The login reponse object is defined as follows.

{
  userName: '<Twitter User Name>',
  userId: '<Twitter User Id>',
  secret: '<Twitter Oauth Secret>',
  token: '<Twitter Oauth Token>'
}

NOTE: This plugin has a fix to a bug appearing in the other twitter cordova plugins which returned userId as an integer which is fine in java but gets truncated in javascript because its too big for a javascript integer and thus this plugin fixed it by converting the user id to string before passing it to javascript which insures that correct userId is retrieved.

See:

https://twittercommunity.com/t/twitter-id-and-id-str-are-different/79942

https://developer.twitter.com/en/docs/basics/twitter-ids

https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object

NOTE: TwitterKit saves user id as a long and doesnt provide it as a string so need to convert to string before sending it to javascript

https://github.com/twitter/twitter-kit-android/blob/master/twitter-core/src/main/java/com/twitter/sdk/android/core/TwitterSession.java#L48

https://github.com/twitter/twitter-kit-android/blob/master/twitter-core/src/main/java/com/twitter/sdk/android/core/Session.java#L45

https://github.com/twitter/twitter-kit-android/blob/master/twitter-core/src/main/java/com/twitter/sdk/android/core/identity/AuthHandler.java#L91

https://github.com/twitter/twitter-kit-android/blob/master/twitter-core/src/main/java/com/twitter/sdk/android/core/models/User.java#L128

https://github.com/twitter/twitter-kit-android/blob/master/twitter-core/src/main/java/com/twitter/sdk/android/core/internal/oauth/OAuthResponse.java#L52

Logout

Logout using the .logout method:

TwitterConnect.logout(
  function() {
    console.log('[Logout] - Successful logout!');
  },
  function() {
    console.log('[Logout] - Error logging out');
  }
);

ShowUser

Show a user's profile information. Returns a JSON object as specified in the API: https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show

TwitterConnect.showUser(

  /*Endpoint arguments*/
  {"include_entities" : false},

  /*Callback functions*/
  function(result) {
    console.log('[ShowUser] - Success!');
    console.log(result);
    console.log('[ShowUser] - Twitter handle: ' + result.screen_name);
  },
  function(error) {
    console.log('[ShowUser] - Error: ' + error);
  }
);

VerifyCredentials

Show's a user's profile information with added details as specified. Returns a JSON object as specified in the API: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials

TwitterConnect.verifyCredentials(

  /*Endpoint arguments*/
  {"include_entities": false,
  "skip_status" : true,
  "include_email": true},

  /*Callback functions*/
  function(result) {
    console.log('[VerifyCredentials] - Success!');
    console.log(result);
  },
  function(error) {
    console.log('[VerifyCredentials] - Error: ' +  error);
  }
);