twitter-dart / twitter-api-v2

The most famous and powerful Dart/Flutter library for Twitter API v2.0 🐦
https://pub.dev/packages/twitter_api_v2
BSD 3-Clause "New" or "Revised" License
167 stars 45 forks source link

`GET /2/tweets/search/recent` support only 'App only' authentication method #619

Closed shinobi-art closed 1 year ago

shinobi-art commented 1 year ago

Hello, Thanks for building an amazing lib,

I have check https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent The official Twitter Developer page say this api support both authentication methods:

But when I use your lib, call searchRecent api, it say 'Only AppOnly token is allowed on this endpoint.'.

Could you please check the api again? Thanks.

github-actions[bot] commented 1 year ago

Thanks for your contribution! :)

myConsciousness commented 1 year ago

Hi @shinobi-art , thanks for your feedback!

I think, this is an official Twitter spec change, previously only App-Only tokens could be used.

Are you interested in this Issue pull request? The following modification allows the use of tokens other than AppOnly :)

From:

  @override
  Future<TwitterResponse<List<TweetData>, TweetMeta>> searchRecent({
    required String query,
    int? maxResults,
    String? nextToken,
    SortOrder? sortOrder,
    DateTime? startTime,
    DateTime? endTime,
    String? sinceTweetId,
    String? untilTweetId,
    List<TweetExpansion>? expansions,
    List<TweetField>? tweetFields,
    List<UserField>? userFields,
    List<PlaceField>? placeFields,
    List<PollField>? pollFields,
    List<MediaField>? mediaFields,
    ForwardPaging<List<TweetData>, TweetMeta>? paging,
  }) async =>
      await super.executeForwardPaginationIfNecessary(
        UserContext.appOnly,
        '/2/tweets/search/recent', // Change Here
        {
          'query': query,
          'max_results': maxResults,
          'next_token': nextToken,
          'sort_order': sortOrder?.name,
          'start_time': startTime,
          'end_time': endTime,
          'since_id': sinceTweetId,
          'until_id': untilTweetId,
          'expansions': expansions,
          'tweet.fields': tweetFields,
          'user.fields': userFields,
          'place.fields': placeFields,
          'poll.fields': pollFields,
          'media.fields': mediaFields,
        },
        paging: paging,
        dataBuilder: TweetData.fromJson,
        metaBuilder: TweetMeta.fromJson,
      );

To:

  @override
  Future<TwitterResponse<List<TweetData>, TweetMeta>> searchRecent({
    required String query,
    int? maxResults,
    String? nextToken,
    SortOrder? sortOrder,
    DateTime? startTime,
    DateTime? endTime,
    String? sinceTweetId,
    String? untilTweetId,
    List<TweetExpansion>? expansions,
    List<TweetField>? tweetFields,
    List<UserField>? userFields,
    List<PlaceField>? placeFields,
    List<PollField>? pollFields,
    List<MediaField>? mediaFields,
    ForwardPaging<List<TweetData>, TweetMeta>? paging,
  }) async =>
      await super.executeForwardPaginationIfNecessary(
 +       UserContext.oauth2OrOAuth1,
        '/2/tweets/search/recent',
        {
          'query': query,
          'max_results': maxResults,
          'next_token': nextToken,
          'sort_order': sortOrder?.name,
          'start_time': startTime,
          'end_time': endTime,
          'since_id': sinceTweetId,
          'until_id': untilTweetId,
          'expansions': expansions,
          'tweet.fields': tweetFields,
          'user.fields': userFields,
          'place.fields': placeFields,
          'poll.fields': pollFields,
          'media.fields': mediaFields,
        },
        paging: paging,
        dataBuilder: TweetData.fromJson,
        metaBuilder: TweetMeta.fromJson,
      );
myConsciousness commented 1 year ago

@all-contributors please add @shinobi-art for bug, question

allcontributors[bot] commented 1 year ago

@myConsciousness

I've put up a pull request to add @shinobi-art! :tada:

shinobi-art commented 1 year ago

Hi @myConsciousness , thank you for feedback me soon! Could you please make a pull request to fix this issue, and release in the next version of the lib(4.7.2). Thanks,