0

Hello i have tweet id's and i saved them to database before. But i saw that i could not save created time efficiently (it is saved like 00:00:00). Therefore i wished to update my tweets with tweet id by using following code.

   MyConnectionBuilder myConnection = new MyConnectionBuilder();
   Twitter twitter = new TwitterFactory(myConnection.configuration.build()).getInstance();
    Status status = twitter.showStatus(Long.parseLong(tweetId));

But it takes too much time to get tweets, is there any rate limit for this ? If there is a rate limit how can i make it faster ?

mstfky
  • 87
  • 1
  • 10

1 Answers1

1

Updating every single tweet via showStatus wastes your "credits" for a given timeframe (rate-limit).

For updating multiple tweets, you should use lookup with a maximum of 100 ids per request. This call will use the /statuses/lookup endpoint.

Rate-Limit and endpoint documentation can be found here

Code-Snipped for it:

Twitter twitter =  twitterFactory.getInstance();
ResponseList<Status> responseList  = twitter.lookup(ArrayUtils.toPrimitive(ids));

    if(responseList != null) {
        for (Status status : responseList) {
            // do what you need to do here

        }
    }       
rzo1
  • 5,561
  • 3
  • 25
  • 64
  • Hello thanks for reply, i will try but what will be input for ids , array ? or list ? i tried but i couldnt find exact input for it. @rzo – mstfky Jun 07 '17 at 12:55
  • Basic Input is Array. Example uses List or Set of Long Values. – rzo1 Jun 07 '17 at 13:38
  • i modified it to be long[] and i removed Arrayutils.toPrimitive method in lookup method i just put my long[] array. Can it be a problem ? @rzo – mstfky Jun 08 '17 at 05:58
  • http://twitter4j.org/javadoc/twitter4j/api/TweetsResources.html#lookup-long...- long array should be fine. – rzo1 Jun 08 '17 at 06:25
  • hi , i could not get any result , ResponseList responseList = twitter.lookup(myIdArray); System.out.println(responseList.size()); size printed as zero. @rzo , what should i do ? thanks for your interest – mstfky Jun 08 '17 at 07:29