简体   繁体   中英

User Mention Timeline Gives 0 Results With twitter-api-v2

Trying to use the user mention timeline via twitter-api-v2 and it always says there are no tweets mentioning the user, I've tested out many different user id's and they all give the same result.

_realData: { meta: { result_count: 0 } }

const getMentions = async () => {
    try {
       const mentions = await rwClient.v2.userMentionTimeline('141664648', { end_time: '2011-11-06T00:00:00-00:00' });
        console.log(mentions);
    } catch (e) {
        console.error(e);
    }
}

getMentions();

outputs

TweetUserMentionTimelineV2Paginator {
  _maxResultsWhenFetchLast: 100,
  _realData: { meta: { result_count: 0 } },
  _rateLimit: { limit: 450, remaining: 449, reset: 1673495653 },
  _instance: TwitterApiv2 {
    _currentUser: null,
    _currentUserV2: null,
    _requestMaker: ClientRequestMaker {
      rateLimits: [Object],
      clientSettings: {},
      bearerToken: '<my bearer token>'
    },
    _prefix: 'https://api.twitter.com/2/'
  },
  _queryParams: { end_time: '2011-11-06T00:00:00-00:00' },
  _sharedParams: { id: '141664648' },
  _endpoint: 'users/:id/mentions'
}

It works fine for userMentionTimeline() in 'twitter-api-v2' It just hard to find a good time slot for user.

Demo Code

import { TwitterApi } from 'twitter-api-v2';

const getMentions = async () => {
    try {
        const twitterClient = new TwitterApi('**************************************');
        const readOnlyClient = twitterClient.readOnly;
        const mentions = await readOnlyClient.v2.userMentionTimeline('415859364', { start_time: '2023-01-12T05:12:01Z', end_time: '2023-01-12T05:20:01Z' });
        return Promise.resolve(mentions.data);
    } catch (error) {
        return Promise.reject(error);
    }
}

getMentions()
    .then((result) => {
        console.log(JSON.stringify(result, null, 4))
    })
    .catch(error => {
        console.error(error);
    });

Result from terminal

在此处输入图像描述

Confirmed by v2 API call by Postman.

在此处输入图像描述

Check the two tweet's time stamp. - It agree with API results.

The API and display time are different due to UTC (API time) and UTC+8 (tweet UI time) difference display but it is same if convert UTC+8 (display) to UTC (API).

https://twitter.com/cielbleu011/status/1613405379060457472

在此处输入图像描述

https://twitter.com/cielbleu011/status/1613405151326527489

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM