Git Product home page Git Product logo

nativescript-twitter's Introduction

Nativescript Twitter

NativeScript implementation of Twitter SDK (Some Features)

npm npm

NS 3.0+

tns plugin add nativescript-twitter

NS < 3.0

npm install nativescript-twitter@"^1.x"

Example Implementation

Android

//app.ts or main.ts
import * as app from "application";
if (app.android) {
    const TNSTwitter = require("nativescript-twitter").TNSTwitter;
    TNSTwitter.init("key", "secret");
}

IOS

Note Twitter Kit looks for a URL scheme in the format twitterkit-<consumerKey>, where consumerKey is your application’s Twitter API key, e.g. twitterkit-dwLf79lNQfsJ.

In your app’s Info.plist, add URL Schemes by adding code below after <dict> Source

// Info.plist
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>twitterkit-<consumerKey></string>
    </array>
  </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>twitter</string>
    <string>twitterauth</string>
</array
//custom-app-delegate.ts
import * as utils from "utils/utils";
declare const UIResponder, UIApplicationDelegate, Twitter;
export class CustomAppDelegate extends UIResponder implements UIApplicationDelegate {
    public static ObjCProtocols = [UIApplicationDelegate];
    applicationDidFinishLaunchingWithOptions(application, launchOptions) {
        utils.ios.getter(Twitter,Twitter.sharedInstance).startWithConsumerKeyConsumerSecret("key" ,"secret");
        return true;
    }
    applicationOpenURLOptions(application, url, options) {
        return utils.ios.getter(Twitter,Twitter.sharedInstance).applicationOpenURLOptions(application, url, options);
    }
}
//app.ts or main.ts
import * as app from "application";
if (app.ios) {
    app.ios.delegate = require('./custom-app-delegate').CustomAppDelegate;
}

IMPORTANT: Make sure you include xmlns:twitter="nativescript-twitter" on the Page tag

<twitter:TNSTwitterButton id="twitter"/>

Listen when user auth is successful or fails

import * as frame from "ui/frame";
 frame.topmost().getViewById('twitter').on('loginStatus', (args) => {
        if (args.object.get("value") === 'failed') {
            console.log(args.object.get("message"))
        } else {
            TNSTwitter.getCurrentUser(args.object.get("userID")).then(
                (user) => {
                    console.dump(user)
                }, err => {
                    console.dump(err)
                })
        }

    });

Send api request

import { CustomApiService } from "nativescript-twitter"
const api = new CustomApiService();
    api.makeRequest("https://api.twitter.com/1.1/account/verify_credentials.json", "get")
        .then(
        data => {
            console.log(data)
        }, err => {
            console.log(err.message)
        });

Angular

import { registerElement } from "nativescript-angular/element-registry";
registerElement("TNSTwitterButton", () => require("nativescript-twitter").TNSTwitterButton);
<TNSTwitterButton id="twitter"/>

nativescript-twitter's People

Contributors

triniwiz avatar

Watchers

 avatar  avatar  avatar

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.