import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Storage } from '@ionic/storage'; import Twit from 'twit'; @Injectable() export class TwitterApiProvider { consumer_key: string = 'UxZkbKotkr8Uc6seupnaZ1kDE'; consumer_secret: string = 'fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq'; access_token_key: string; access_token_secret: string; client; constructor(public http: HttpClient, private storage: Storage) { console.log('Hello TwitterApiProvider Provider'); Promise.all([this.storage.get('accessTokenKey'), this.storage.get('accessTokenSecret')]).then(values => { this.access_token_key = values[0]; this.access_token_secret = values[1]; this.initApi(); }); } private initApi() { this.client = new Twit({ consumer_key: this.consumer_key, consumer_secret: this.consumer_secret, access_token: this.access_token_key, access_token_secret: this.access_token_secret, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. }) } public fetchHomeFeed() { return this.client.get('statuses/home_timeline') .then(res => { return res; }) .catch(err => { console.log(err); }); } }