Follow below steps to retrieve your recent tweets:
Step 1: Create a twitter account.
Step 2: Create your app on Twitter and generate keys and tokens. Follow steps here.
Step 3: Add following code:
public class TwitterAPITest
{
String consumerKey = "";
String consumerSecret = "";
String accessToken = "";
String tokenSecret = "";
@BeforeClass
public void setup()
{
RestAssured.baseURI = "https://api.twitter.com";
RestAssured.basePath = "/1.1/statuses";
}
/*Post request example*/
@Test(enabled=true)
public void getExample()
{
Response res =
given()
.auth()
.oauth(consumerKey, consumerSecret, accessToken, tokenSecret)
.queryParam("screen_name","tgoswami013")
.header("Content-Type","application/json")
.when()
.get("/user_timeline.json")
.then()
.statusCode(200)
.extract().response();
System.out.println(res.body().prettyPrint());
}
Wed, 09/02/2020 - 00:00
Tarun Goswami is a highly experienced professional, currently serving as Technical Lead at a well-established IT services company. With over 12 years of experience across multiple domains, he demonstrates his expertise and passion for the industry through his engaging and informative blog writing in his spare time.
Comments