I will pass the user name called John from Salesforce to Twitter. There can be multiple Twitter Accounts available with the name John. I need to fetch all those Accounts from Twitter with the Ids whose name is John.

Below is the second step -

After getting all the Twitter Accounts with the name John, we will select one among those and pass the selected name to Twitter for getting the recent tweets for selected Account.

Please let me know if it is making sense.

Also I have found the URL for search - https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2

(reformatted your post so the code was clearer - there’s a toolbar in the editor which lets you quote and markup code easily)

There are a bunch of issues here.

First of all, you need to sort out the OAuth problem. If you are getting a status forbidden you need to ensure your consumer keys and tokens are correctly configured, your machine’s time is accurate and close to the server (OAuth is time-dependent), and you have configured the library you are using properly. If you use a known API library then most of the heavy lifting for authentication will be done for you.

You said you want to SEARCH for users. In that case take a look at users/search but be aware there may be a wide range of results if you simply ask for all users with “John” in their profile, and you’ll end up paging through them. I think you’d be better passing a known Twitter handle to users/show.

See the REST API reference - there are a bunch of relevant methods that could be useful.

The “search” you refer to on the timeline API is really just requesting that specific user’s timeline, with two Tweets shown.

It is probably worth looking for a library that supports OAuth for you rather than you trying to build out that URL via string concatenation - you’ll need to set appropriate headers and other things as well if you are trying to do OAuth by hand.