Displaying tweets using dynamic twitter handle


Hi Everyone,

I am seeking some help in embedding a twitter timeline on my page. The issue which I am facing is around using dynamic twitter handle. I need to implement a solution where I can bind a frame on my page with twitter handle and latest feeds for that twitter handle should be displayed. However, I am not able to pass the twitter handle dynamically to that frame. I am able to bind constant twitter handle but not the dynamic one.

Any help/pointers will be appeciated


You can use HTML markup or a JavaScript factory function.

Create HTML markup passing in the desired username and a widget ID you have configured on Twitter.com:

<a class="twitter-timeline"
Tweets by @{username}

Or dynamically create the timeline with a JavaScript factory function:

    screenName: {username}


Hi Niall,

Thanks a lot for replying on this thread. Will I need to setup any authentication with twitter corresponding to the twitter handle, or using this code, I can just pass the twitter handle, and twitter timeline corresponding toi the same will be displayed on my page.

Thanks Again,


Just to make myself more clear, I’ll picking up the twitter handle from an external system. So I won’t be able to setup any widget id on twitter. I need to pick a twitter handle and tweets should be displayed for that handle.



You would need to set up a widget ID once for your website to store a widget configuration on Twitter’s servers. You would then use that widget ID in your HTML markup or JavaScript factory function with a username override to swap in a specific username for your display case.


Hi Naill,

In your JavaScript factory function example, what if I don’t have a widget ID.

And if the widget ID is mandatory is there any way to create it dynamically.



The widget ID is mandatory.


Hi Nail,

What we are getting from the code snippet provided by you is that widget id is mapped with the username and in order to display the timelines, we need to configure the widget id in advance for that username. However, if I am not having username in advance and if I am getting the same in real time scenario, is there a way to create widget id dynamically for that username and displaying the timeline for that username.

Manu Goyal


No, it is not possible to dynamically create a widget ID. You should select a username for the site or service when creating a user timeline widget; that username will act as a fallback if not overridden in your widget display or if the username you provide as an override is invalid.


Hi Niall,

Thanks a lot for your reply. I understand that there we can’t be able to use widget for our problem statement. I just want to check around any REST based API exposed by Twitter on this which we can call from our code to get the twitter timeline corresponding to a username.



You need GET statuses/user_timeline