0

I'm learning to create very simple and basic angular applications. I've decided to show my tweets from my twitter timeline. I followed some youtube tutorials and some blogs. Specially this- Connect to the Twitter API in an Angular 6 App. I was able to create a basic working angular-twiiter app (a made up name). I'll show you my code:

server.js (nothing wrong with this code)

const express = require('express');
const Twitter = require('twit');
const app = express();

app.listen(3000, () => console.log('Server running'));

const api_client = new Twitter({
    consumer_key: 'MY_KEY',
    consumer_secret: 'MY_SECRET_KEY',
    access_token: 'MY_TOKEN',
    access_token_secret: 'MY_SECRET_TOKEN'
})

app.get('/home_timeline', (req, res) => {
    const params = { tweet_mode: 'extended', count: 10 };

    api_client
      .get('statuses/home_timeline', params)
      .then(timeline => {
        res.send(timeline);
      })
      .catch(error => {
      res.send(error);
    });
});

Then I created twitterservice.service.ts (error in this code)

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class TwitterserviceService {

  api_url = 'https:/localhost:3000';

  constructor(private http: HttpClient) { }

  getTimeline() {
    return this.http
      .get<any[]>(this.api_url+'/home_timeline')
      .pipe(this.map(data => data));  //ERROR: Property 'map' does not exist ...
  }
}

For map I'm getting:

Property 'map' does not exist on type 'TwitterserviceService'.

However, My server.js is working absolutely fine. I've tested it on Postman and I'm getting the desired JSON output. I tried finding help on the internet, read some articles and questions like: Property 'map' does not exist on type 'Observable'. But still I'm not able to solve this. Please correct me.

Tanzeel
  • 4,174
  • 13
  • 57
  • 110

1 Answers1

1

Replace this.map with map. Using this keyword implies map is a member variable of 'TwitterserviceService' service.

ruth
  • 29,535
  • 4
  • 30
  • 57
  • Such a stupid mistake I did. I'm accepting this answer. And I'm so sorry I bothered you for this. :-( – Tanzeel Feb 15 '20 at 23:07
  • And also I missed adding `import { map } from 'rxjs/operators';`. I added it later. This was also the issue. – Tanzeel Feb 16 '20 at 03:40
  • Well, the import statement is included in the original question however. Its all good as long as you got it working. – ruth Feb 16 '20 at 04:03