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

How to get nearby location information? #577

Closed normidar closed 1 year ago

normidar commented 1 year ago

1. Problem to solve

Get nearby location information。

how to use this API: https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/overview

2. Proposal

3. More information

github-actions[bot] commented 1 year ago

Thanks for your contribution! :)

normidar commented 1 year ago

it like a v1 API:

https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-reverse_geocode

I think I can use http package.

get the id and create a GeoParam.

myConsciousness commented 1 year ago

Hi @normidar ,

Geo-related v2 endpoints are not officially supported, so this package also does not currently support endpoints that manipulate them either.

Well, as we can read from the name, this package supports only v2 endpoints. I made an exception and implemented Media using the v1 endpoint because official Twitter will not support this high demand v2 endpoint anytime soon.

So, this package has a flexible structure that can accommodate even v1 endpoints, of course :) I can also implement and release it using v1 endpoints if there is a demand for it :)

However, please keep note that destructive changes may occur when the v2 endpoint, the actual successor to this v1 endpoint, is officially released.

myConsciousness commented 1 year ago

@all-contributors please add @normidar for ideas

allcontributors[bot] commented 1 year ago

@myConsciousness

I've put up a pull request to add @normidar! :tada:

normidar commented 1 year ago

@myConsciousness

So, this package has a flexible structure that can accommodate even v1 endpoints, of course :) I can also implement and release it using v1 endpoints if there is a demand for it :)

It sounds good, how long will it take? before that, I think will use the v1 by REST Get.

normidar commented 1 year ago

it is difficult to authenticate the HTTP access for me. I will wait for your work.

myConsciousness commented 1 year ago

Hi @normidar ,

I have already completed the implementation of these endpoints, so I will release it as soon as testing is completed, maybe it's in 2 days or less :)

Please see #578 also!

myConsciousness commented 1 year ago

Hi @normidar ,

v4.5.0 with Geo service support has been released :) You can search for places as follows.

import 'package:twitter_api_v2/twitter_api_v2.dart' as v2;

Future<void> main() async {
  final twitter = v2.TwitterApi(
    bearerToken: 'YOUR_TOKEN_HERE',

    //! OAuth 1.0a tokens are required for v1.1 endpoint.
    oauthTokens: v2.OAuthTokens(
      consumerKey: 'CONSUMER_KEY',
      consumerSecret: 'CONSUMER_KEY_SECRET',
      accessToken: 'ACCESS_TOKEN',
      accessTokenSecret: 'ACCESS_TOKEN_SECRET',
    ),
  );

  try {
    final response = await twitter.geo.searchLocations(
      query: 'Tokyo',
    );

    print(response);
    print(response.data.first.id);
  } on v2.TwitterException catch (e) {
    print(e);
  }
}

And you can lookup a specific place data by place id.

import 'package:twitter_api_v2/twitter_api_v2.dart' as v2;

Future<void> main() async {
  final twitter = v2.TwitterApi(
    bearerToken: 'YOUR_TOKEN_HERE',

    //! OAuth 1.0a tokens are required for v1.1 endpoint.
    oauthTokens: v2.OAuthTokens(
      consumerKey: 'CONSUMER_KEY',
      consumerSecret: 'CONSUMER_KEY_SECRET',
      accessToken: 'ACCESS_TOKEN',
      accessTokenSecret: 'ACCESS_TOKEN_SECRET',
    ),
  );

  try {
    final response = await twitter.geo.lookupById(
      placeId: '1234',
    );

    print(response);
    print(response.data.id);
  } on v2.TwitterException catch (e) {
    print(e);
  }
}
myConsciousness commented 1 year ago

Fixed #581

normidar commented 1 year ago

@myConsciousness

Thanks for your work.

Can I use /1.1/geo/reverse_geocode here?

I am trying

final res = await api.geo.searchLocations(
            granularity: GeoGranularity.neighborhood,
            latitude:****,
            longitude: ******,
          );

but I got

[埼玉 所沢市, 埼玉 川越市, 埼玉 さいたま市 大宮区,....

It is too broad, I just want to search for the store that is near me.

normidar commented 1 year ago

@myConsciousness If you do not mind, I think I can try to create a PR for this.