# twitter4j **Repository Path**: mirrors/twitter4j ## Basic Information - **Project Name**: twitter4j - **Description**: Twitter4J 是一个非官方的 Twitter API 的 Java 客户端开发包,使用 Twitter4j 可以轻松在你的应用中集成 Twitter 的服务,主要特点: 10 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2019-08-08 - **Last Updated**: 2023-08-17 ## Categories & Tags **Categories**: web-dev-toolkits **Tags**: None ## README # X4J [#Twitter4J](https://twitter.com/search?q=%23twitter4j&src=typed_query&f=live) is a 100% pure Java library for the Twitter API with no extra dependency. [![@t4j_news](https://img.shields.io/twitter/url/https/twitter.com/t4j_news.svg?style=social&label=Follow%20%40t4j_news)](https://twitter.com/t4j_news) ## Requirements Java 8 or later ## Dependency declaration Add a dependency declaration to pom.xml, or build.gradle as follows: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.twitter4j/twitter4j-corej/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.twitter4j/twitter4j-core) ### Maven ```xml org.twitter4j twitter4j-core 4.1.2 ``` ### Gradle ```text dependencies { compile 'org.twitter4j:twitter4j-core:4.1.2' } ``` ### Java modularity ```text requires org.twitter4j; ``` ## Getting started Acquire an instance configured with twitter4j.properties, tweet "Hello Twitter API!". #### twitter4j.properties ```properties oauth.consumerKey=[consumer key] oauth.consumerSecret=[consumer secret] oauth.accessToken=[access token] oauth.accessTokenSecret=[access token secret] ``` #### Main.java ```java import org.twitter4j.*; public class Main { public static void main(String... args){ Twitter twitter = Twitter.getInstance(); twitter.v1().tweets().updateStatus("Hello Twitter API!"); } } ``` v1() returns [TwitterV1](https://github.com/Twitter4J/Twitter4J/blob/main/twitter4j-core/src/v1/java/twitter4j/v1/TwitterV1.java) interface which provides various Twitter API V1.1 API resources. tweets() returns [TweetsResources](https://github.com/Twitter4J/Twitter4J/blob/main/twitter4j-core/src/v1/java/twitter4j/v1/TweetsResources.java). You can also get a builder object from newBuilder() method to configure the instance with code: #### Main.java ```java import org.twitter4j.*; public class Main { public static void main(String... args){ var twitter = Twitter.newBuilder() .oAuthConsumer("consumer key", "consumer secret") .oAuthAccessToken("access token", "access token secret") .build(); twitter.v1().tweets().updateStatus("Hello Twitter API!"); } } ``` ## License Apache License Version 2.0 ![Java CI with Gradle](https://github.com/Twitter4J/Twitter4J/workflows/Java%20CI%20with%20Gradle/badge.svg)