redouane59 / twittered

Twitter API client for Java developers
Apache License 2.0
236 stars 64 forks source link

Can i set proxy? #300

Closed shiwangsimba closed 2 years ago

shiwangsimba commented 2 years ago

Can i set proxy?Otherwise, I will always report errors: Connection timed out: connect

redouane59 commented 2 years ago

What do you mean exactly ?

shiwangsimba commented 2 years ago

like: setProxy("xxx.xxx.xxx.xxx"); setPort("8080");

There may be some problems with my network. I can open twitter in Google, but the running code will report an error. It says that the connection time out. I found some solutions elsewhere, saying it is a proxy problem

image

shiwangsimba commented 2 years ago

image like this.This is the library of twitter 4J. I want to use the function of searching all tweets, but it doesn't have this function, so I replaced your library, but what's more embarrassing is that I can't use the proxy function

redouane59 commented 2 years ago

Maybe you can set it up directly using your own HttpClient ?

Like TwitterClient twitterClient = new TwitterClient(twitterCredentials, getServiceBuilder(twitterCredentials.getApiKey()));

  private ServiceBuilder getServiceBuilder(String apiKey) {
    Builder httpBuilder = new Builder()
        .addNetworkInterceptor(new CacheInterceptor())
        // see if you can add here proxy info
    OkHttpHttpClient okHttpClient = new OkHttpHttpClient(new OkHttpHttpClientConfig(httpBuilder));
    return new ServiceBuilder(apiKey)
        .httpClient(okHttpClient);
  }
shiwangsimba commented 2 years ago

thank you , According to your prompt, I finally solved the problem like this image

but why I can get the data normally with "searchTweets", but the result returned by "searchAllTweets" is null

redouane59 commented 2 years ago

Maybe because you don't have an authorised account ? Please check the error logs.

shiwangsimba commented 2 years ago

Maybe because you don't have an authorised account ? Please check the error logs.

no,There is no error. When I use "searchTweets", the console outputs data, but when I use "searchAllTweets", there is no output, but the program runs normally without error. When I debug at breakpoint, I find that the "data" and other properties of the variable "result" are null

image

shiwangsimba commented 2 years ago

image image

What I don't understand is that the strings I search are the same. Why do I use "searchTweets" and "searchAllTweets" have different results

redouane59 commented 2 years ago

Because searchAllTweets is only for premium Twitter API accounts, and the time frame is not the same. If you don't have a premium account, you won't be able to use this API. If you check the error logs you will see it.

shiwangsimba commented 2 years ago

Because searchAllTweets is only for premium Twitter API accounts, and the time frame is not the same. If you don't have a premium account, you won't be able to use this API. If you check the error logs you will see it.

ok...I see. Thank you for your reply