Search code examples
angulartypescriptlinq-to-twitter

How to use large numbers in angular 5+?


I am using angular 5 with .Netcore 2.0. I am using the API controller to process tweets(LinqToTwitter). The tweets comes through my typescript from the controller all fine apart from the statusID which is 19 digits long.

The statusID should be: XXXXXXXXXXXXXXXX573

but it is coming through to type script as: XXXXXXXXXXXXXXXX600

API controller:

[HttpPost("[action]")]
public async Task<Search> GetAllTweetsByNamePost([FromBody] SearchQuery searchQuery)
{
    searchVal = searchQuery.Name;
    Twitter twit = new Twitter();
    twit.Initialise();
    var t = await twit.Fetch(searchVal, 50, true, SearchType.Search);
    return t[0];
}

When I check the Status ID in the controller it shows the correct ID but But the time it gets to the TS statusID is different and there is a pattern in the numbers.

the first 16 digits are correct and the last 3 increments by 100 e.g.

XXXXXXXXXXXXXXXX100 XXXXXXXXXXXXXXXX200 XXXXXXXXXXXXXXXX300

In the Api controller I am using the LinqToTwitter Status object. The type of the property in the Status object is public ulong SinceID { get; set; } and I have set the property Of the TS Model is statusID: any;

getSocialDataTwitter(searchQuery) {
    const headers = new HttpHeaders().set('content-type', 'application/json');
    return this.http.post<LeftOperatorPaneltwitter>(this.baseUrl + 'api/OperationData/GetAllTweetsByNamePost', '{"Name":"' + searchQuery + '"}', { headers }).subscribe(result => {
      this.tweets = result;
      result.statuses.forEach(search => {
        console.log(search.statusID + ' This is my Status ID');
      })
    }, error => console.error(error));
  }

Solution

  • Javascript cannot handle numbers of such a length. According to this, the maximum safe integer value is: 9007199254740991. I'd suggest representing your ID as a string.