Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:04:58+00:00 2026-06-17T13:04:58+00:00

I am trying to work with an oauth library for javascript to fetch tweets

  • 0

I am trying to work with an oauth library for javascript to fetch tweets . I have created an object that takes in the url for the twitter timeline to fetch and puts it in a column. The code is

   lister=function(opts) {
    this.setresource =lister.setresource;
    this.config = lister.config;
    this.config.resource = opts;
    this.putTweet = lister.putTweet;
    this.listerstrap = lister.listerstrap;
    this.addStrip = lister.addStrip;
    this.setTweets = lister.setTweets;
    this.addTweets = lister.addTweets;

}    

Now, if I create two new objects of lister ,

    var l1 = new lister('user1'); //user1 and user2 refer to url of the timelines 
    l1.listerstrap();
    var l2 = new lister('user2');
    l2.listerstrap();

The listerstrap function is :

     lister.listerstrap = function () {
   this.addStrip().setresource().addTweets();

   }

The problem happens in addTweets()

     lister.addTweets = function () {

   var _ = this;
   oauth.get(twiapi + _.config.resource, function (res) {
       _.setTweets(JSON.parse(res.text));
       console.log(_.config.resource);  // * 
   });

At * , the this (_) refers to the same (l2 instance) and hence the tweets from both resources are set into the same column when setTweets is called

Is this a closure problem ?

Edit: I am trying to set tweets into different columns based on the timeline or lists(as is done in say Tweetdeck , where there is a different column for each list). Though I get the tweets from both urls but they are set into the same column. _ contains the reference to the div element for each column I created in addStrip(). But somehow _ refers to the same instance in the callback . I want it to set the tweets into their respective columns

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:04:59+00:00Added an answer on June 17, 2026 at 1:04 pm

    The problem isn’t the addTweets method, if you read my previous answer: forget about it.

    The problem is this:

    this.config = lister.config;
    this.config.resource = opts;
    

    your constructor assigns a reference to an object, the object itself is not copied. So by assigning a reference to an instance, and then changing the referenced object, you’re changing the object that is referenced by all instances.

    The quick fix would be to change this.config = lister.config; to something like:

    this.config = {foo: 'bar', something: 'else', resource: opts};//each time the constructor is called, create a new object literal
    

    But please, do look into working with prototypes, because assigning references to properties of the function object, that also doubles as a constructor is not the best approach.

    Update:

    In response to the OP’s comment: What you’re seeing makes perfect sense. You’re creating a new instance, setting the single config.resource object (there is only one) to User1, and the addTweets function is invoked. This function performs an asynchronous request. Asynchronous is something that is all too often overlooked, but very important in this case: before the callback function (that uses the config.resource value) is invoked, you create a new instance, and then the config.resource property is changed. The callback function isn’t invoked ’till after the second instance is constructed. That’s why the config.resource value is changed in that split second between calling addTweets and the async callback being invoked, because that’s when the second instance is created. It’s as simple as that, really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get twitter update_profile_image to work using OAuth. I was using curl
I've been trying to get OAuth for Twitter to work on my iPhone application
I am trying to make work twitter oAuth with twitterizer, but I am unable.
I am trying to better understand the work-flow of the Twitter Oauth implementation. Currently,
I'm trying to build a portable class library that generates OAuth urls for other
Trying to work with groupby so that I can group together files that were
We're trying to get 2-legged OAuth to work with the Gmail atom feed. We're
So I'm trying to get the oauth authlogic plugin (https://github.com/jrallison/authlogic_oauth) to work on my
I am trying to get the OAuth gem to work with Rails 3 and
I'm trying to figure out Foursquare's OAuth so I can have a user sign

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.