Skip to content

Instantly share code, notes, and snippets.

@mertguner
Last active January 27, 2020 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mertguner/697a49b35c941173547b67573c0b3bcd to your computer and use it in GitHub Desktop.
Save mertguner/697a49b35c941173547b67573c0b3bcd to your computer and use it in GitHub Desktop.
-----------------------Pom.xml-----------------------
<dependency>
<groupId>com.github.seratch</groupId>
<artifactId>signedrequest4j</artifactId>
<version>2.14</version>
</dependency>
-----------------------Pom.xml-----------------------
-----------------------Postman Authorization-----------------------
Type = OAuth 1.0
Add authorization data to = Request Headers
Consumer Key = {API key}
Consumer Secret = {API secret key}
Access Token = {Access token}
Token Secret = {Access token secret}
-----------------------Postman Authorization-----------------------
-----------------------Java Class-----------------------
OAuthConsumer consumer = new OAuthConsumer("{API key}", "{API secret key}");
OAuthAccessToken accessToken = new OAuthAccessToken("{Access token}", "{Access token secret}");
SignedRequest threeLeggedOAuthRequest = SignedRequestFactory.create(consumer, accessToken);
Map<String, Object> requestParameters = new HashMap<String, Object>();
-----------------------Send Tweet-----------------------
HttpResponse response = threeLeggedOAuthRequest.doPost("https://api.twitter.com/1.1/statuses/update.json?status=HelloTest", requestParameters, "UTF-8");
int status = response.getStatusCode(); // -> int
String body = response.getTextBody(); // -> String
-----------------------Send Tweet-----------------------
-----------------------Get timeline-----------------------
HttpResponse response = threeLeggedOAuthRequest.doGet("https://api.twitter.com/1.1/statuses/home_timeline.json", "UTF-8");
int status = response.getStatusCode(); // -> int
String body = response.getTextBody(); // -> String
-----------------------Get timeline-----------------------
-----------------------Delete Tweet-----------------------
HttpResponse response = threeLeggedOAuthRequest.doPost("https://api.twitter.com/1.1/statuses/destroy/1219345101828378625.json", requestParameters, "UTF-8");
int status = response.getStatusCode(); // -> int
String body = response.getTextBody(); // -> String
-----------------------Delete Tweet-----------------------
-----------------------Start DM-----------------------
POST https://api.twitter.com/1.1/direct_messages/events/new.json
-----------------------application/json Body
{
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "78054600"
},
"message_data": {
"text": "Api ile DM Başlatma Testi"
}
}
}
}
-----------------------application/json Body
-----------------------Start DM-----------------------
-----------------------Java Class-----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment