Skip to main content

Retrieve your recent Tweets using REST Assured GET Request

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());
	}

Submitted by tgoswami on September 2, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.