redouane59 / twittered Goto Github PK
View Code? Open in Web Editor NEWTwitter API client for Java developers
License: Apache License 2.0
Twitter API client for Java developers
License: Apache License 2.0
Hi, would it be possible to extend the Tweet class to be able to get the following information:
Hi folks,
this is real good software. Is it open source? If so, could you please add an open source license so that I know how I may use this library?
Best...
Matthias
Hi;
Thank you for your awesome work.
I made my Twitter client for Android using another library. I came by your twitter library from Twitter developer site. I am planning to do a desktop application that can work on both windows and mac platforms, my question is, how to do callback function so it can retrieve the access token from the web after my app been authorized by the user?
Is there is any example/documentation for doing such a thing?
Thanks.
I just discovered this java client library. Looks cool.
However, I was unable to find any information about tweeting text from this library.
Is this feature available that I am not able to see or it is not implemented yet?
Hello from Twitter Developer Relations!
First of all: Thank You, for building on our API, and for supporting our developer communities! You, and many projects like this one, are among the reasons why Twitter data is much-appreciated by developers. We historically haven't built libraries and SDKs - the communities, YOU, have done so - and I'm here to tell you how much we appreciate that, and that we know you're around!
As you already know, we are currently building a brand new API platform that (over time) will replace the current one. I would love to connect with you on any plans to add support for Twitter Developer Labs to twitter-lite! We're looking to be much more focused on proper API versioning, and are basing our specification on OpenAPI.
We would really love to continue to work with you so as you continue to help the Java community. Thank you, again!
Hi, I can't upload media to Twitter using twitterClient.uploadMedia() - is there something special to consider?
After building the twitterClient with the TwitterCredentials builder() and adding the 4 secrets/keys I execute the following code:
String filename = "twitter.png"
File mediaFile = new File(filename)
assert mediaFile.exists() == true
UploadMediaResponse mediaResponse = twitterClient.uploadMedia(mediaFile, MediaCategory.TWEET_IMAGE)
The resulting mediaResponse exists but has no mediaId (null) and size of 0.
Btw. reading users and tweets works.
For the users who don't want to use api key / secret key
@sparack
Hey there,
I'm trying to use the filtered stream in v2 yet it isn't returning any tweet.
if(twitterClient.retrieveFilteredStreamRules() != null) {
twitterClient.deleteFilteredStreamRule("from:CharSequence");
twitterClient.addFilteredStreamRule("from:CharSequence","from:CharSequence");
System.out.println("Added rule");
}
try {
System.out.println("Started filtered stream");
twitterClient.retrieveFilteredStreamRules().forEach(streamRule -> {
System.out.println(streamRule.getValue());
});
Future<Response> future = twitterClient.startFilteredStream(System.out::println);
try {
future.get(5, TimeUnit.SECONDS);
} catch (TimeoutException exc) {
exc.printStackTrace();
}
} catch (Exception exception) {
exception.printStackTrace();
}
It should at least return a tweet from my twitter account yet it doesn't return anything, yet the rules are set. Any idea as to why?
There is a case when the Consumer is triggered on data that is not a JSON tweet but more like a notification for a limitation.
The problem occurs in RequestHelperV2.onResponse(Call call, final Response response), when trying to map the json to a TwitterV2.class, both data & includes properties will be null.
Here is the json received:
{
"title":"ConnectionException",
"detail":"This stream is currently at the maximum allowed connection limit.",
"connection_issue":"TooManyConnections",
"type":"https://api.twitter.com/2/problems/streaming-connection"
}
When this happens, the stream is disconnected.
You can easily reproduce the problem when starting two twitterclient instance using the same credentials and opening a stream.
I think firing some new Consumer<TwitterError>
would be a good approach, and let the developper handle the error & reconnect the stream.
for example :
twitterClient.startFilteredStream(consumer, errorConsumer);
I'll try to provide a pull request based on your return. (i'm in a rush, so i don't know when).
See redouane59/twitter-personal-analyzer-bot#5 (comment)
thanks @hypr2771 for the feedback
Currently when deploying only the unit tests are performed but there are no integration tests. Tests in classes like ITwitterClientV2Test are all disabled because it requieres twitter account credentials to be working fine...
How can we manage this ? Does TravisCI can host securely some credentials that we could use for integration tests ?
Example of test :
@Test
public void testFollowAndUnfollow() {
User user = twitterClient.getUserFromUserName("red1");
FollowResponse followResponse = twitterClient.follow(this.userId, user.getId());
assertTrue(followResponse.getData().isFollowing());
assertFalse(followResponse.getData().isPending_follow());
FollowResponse unfollowResponse = twitterClient.unfollow(this.userId, user.getId());
assertFalse(unfollowResponse.getData().isFollowing());
assertEquals(RelationType.NONE, twitterClient.getRelationType("92073489", "66533"));
}
Calling recent search 7 days endpoint with next_token parameter, the API response is always empty.
Missing parameter assign(put) in getOAuth1AccessToken(requestToken, verifier):
parameters.put("oauth_token", requestToken.oauthToken);
Would be great if mute/unmute endpoints get implemented in the next upcoming version.
public static final String
to be modified
(POST) Error calling https://api.twitter.com/2/tweets/search/recent {"errors":[{"parameters":{"tweet.fields":
["tweet.fields=attachments,author_id,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,public_metrics,referenced_tweets,source,text,withheld,context_annotations,conversation_id,reply_settings"]}
,"message":"The `tweet.fields` query parameter value [tweet.fields=attachments] is not one of [attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,non_public_metrics,organic_metrics,possibly_sensitive,promoted_metrics,public_metrics,referenced_tweets,reply_settings,source,text,withheld]"}],"title":"Invalid Request","detail":"One or more parameters to your request was invalid.","type":"https://api.twitter.com/2/problems/invalid-request"} - 400
Find a name more personal.
Impacts :
I have cloned twittered project and when I try to use it I get errors from TwitterClient.java, and when I opened it up it found out that a lot of getter and setters are missing
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
In the version 1.0 of the user's object model, I see those fields related with the user's name:
Then in the version 2.0 of the user's object model, those are the attributes:
screen_name
of the version 1.0).The problem is the Java DTO has only one attribute name
mapped to the JSON attributes screen_name
and username
, meaning the JSON attribute name
is being ignored and the first ones are wrongly mapped.
My suggestion is mapping the JSON attributes screen_name
and username
to the Java DTO username
and map the JSON attribute name
to a new DTO attribute name
.
Is the ability to block a user part of the current functionality?
It would be awesome to include functionality for adding and deleting stream rules.
Endpoint: POST /2/tweets/search/stream/rules
https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules
Is it possible to add a feature to send different get parameters to the request as the samples stream provides these features ?
I see that in the class URLHelper.java , getFilteredStreamUrl() already has these fields appended.
I am using a local build currently for these fields. I can submit a pull request with these changes if it is ok.
Instantiate only once the OkHttp client in RequestHelper
class. See #120
Hello,
It seems that the client currently supports only text tweets. Do you plan to add support of images and other media types?
hi,
Im trying to get a all the tweets data(media, id ...) with the all the user data (name , profile picture..)
so I wrote this code :
twitterClient.getUserFromUserName(username)
and it returns:
com.github.redouane59.twitter.dto.user.UserV2@62cfe06c
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.teamo.myapplication, PID: 20367 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.teamo.myapplication/com.teamo.myapplication.DisplayTwitterNots}: java.util.NoSuchElementException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3762) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3938) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2277) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) Caused by: java.util.NoSuchElementException at com.github.redouane59.twitter.helpers.-$$Lambda$_8WOp8kDeNBzPknjyivyeUPODww.get(Unknown Source:2) at java.util.Optional.orElseThrow(Optional.java:286) at com.github.redouane59.twitter.helpers.RequestHelperV2.getBearerToken(RequestHelperV2.java:128) at com.github.redouane59.twitter.TwitterClient.getBearerToken(TwitterClient.java:666) at com.teamo.myapplication.DisplayTwitterNots.testSearchTweets7days1(DisplayTwitterNots.java:89) at com.teamo.myapplication.DisplayTwitterNots.onCreate(DisplayTwitterNots.java:85) at android.app.Activity.performCreate(Activity.java:8183) at android.app.Activity.performCreate(Activity.java:8167) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3735) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3938) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2277) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8425) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) I/Process: Sending signal. PID: 20367 SIG: 9
I want to display a tweet I have just posted, How to retrieve the avatar image url using the twitter client?
It seems it is possible in v1.1 but not implemented: https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/follow-search-get-users/api-reference/get-users-show
See : #156
Regression, it was working at least until v1.12
Error is :
{"errors":[{"value":"123","parameter":"id","resource_type":"user","section":"data","title":"Authorization Error","detail":"Sorry, you are not authorized to see the user with id: [123].","type":"https://api.twitter.com/2/problems/not-authorized-for-resource"}]}
As @hypr2771 was suggesting, we have to use an argument containing the credentials file path like :
-Dtwitter.credentials.file.path=/my/path/to/json
instead of working with a fixed path in resources folder.
Without it, the external lib should not work.
Find a way to manage credentials directly in code instead of using java program arguments.
Thanks for the suggestion @suhemparack
When calling these V2 endpoints with date parameters, the API answers with a 503 error Service Unavailable.
Currently the methods like searchForTweetsWithin7days
only allow to get a fix result size (100). It would be better to give the user the possibility to make several calls using a next_token
got on the method turn to retrieve more tweets.
Ex: getFavorites()
from ITwitterClientV1
The param tweet_mode
only applies to V1 and can be applied to any endpoint, e.g.
https://api.twitter.com/1.1/favorites/list.json?count=200&screen_name=gabac&tweet_mode=extended
which makes sure that tweets are no longer truncated.
sonar-maven-plugin
jacoco-maven-plugin
com.google.api-client
logback-classic
2 http clients instead of 1 or even 0:
apache http client and okhttp
I am excited about the new twitter-client, but it unfortunately makes Android Studio unhappy.
Unsupported class file version: 56
https://developer.android.com/studio/write/java8-support#supported_features
Any plans to eventually support JDK 8?
Thanks!
When calling some endpoint (i.e: getTweet) outside unit test (e.g in a main class), the connection is not closed after usage and the program never ends.
@sparack
Is there any plan to add direct message related end points?
Sending message events
To send a new Direct Message use POST direct_messages/events/new (message_create). Optionally, you may also attach Quick Replies or media (image, GIF or video).
Hi all, I was working on a retrofit client for twitter and found your repository listed on twitter website.
It seems this is still under active development, do you know if it's ready for production use? We use spring boot 1.5.9
Edit
After a first trial, it's easy to get going with posting a tweet. However, the current TwitterClient.java
is not yet implementing many methods, for example, it force you to use only one media in media_ids
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.