Nighttime Peanut Migrations

    ngx-twitter-api
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    ngx-twitter-api

    Angular service of authorized request for twitter.

    Installation

    Install through npm:

    npm install --save ngx-twitter-api

    Usage

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { HttpModule } from '@angular/http';
     
    import { AppComponent } from './app.component';
    import { TwitterService } from 'ngx-twitter-api';
     
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule
      ],
      providers: [TwitterService], // Add
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    import { Component } from '@angular/core';
    import { TwitterService } from 'ngx-twitter-api';
     
    @Component({
      selector: 'app-root',
      template: `
            <h1>{{title}}</h1>
            <button (click)="getHomeTimeline()">get/home_timeline</button>
            <p>{{result}}</p>
        `
    })
    export class AppComponent {
      title = 'app works!';
      result = '';
      constructor(private twitter: TwitterService){ }
     
      getHomeTimeline(){
        this.twitter.get(
          'https://api.twitter.com/1.1/statuses/home_timeline.json',
          {
            count: 5
          },
          {
            consumerKey: 'consumerKey',
            consumerSecret: 'consumerSecret'
          },
          {
            token: 'token',
            tokenSecret: 'tokenSecret'
          }
      ).subscribe((res)=>{
          this.result = res.json().map(tweet => tweet.text);
      });
      }
    }

    Note

    In Web browser, JavaScript application cannot access external domain server because of Cross-Origin Resource Sharing.

    This service supposes to be used in Cordova, Electron, Chrome Extensions or web security disabled browser.

    Install

    npm i ngx-twitter-api

    DownloadsWeekly Downloads

    18

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    31.4 kB

    Total Files

    13

    Last publish

    Collaborators

    • edyap