Can't reply to tweet using spring social twitter

java
reply
spring

#1

Hi Everyone,

I am trying to build an java webapp where I can see tweets and reply to them. As of now, I am able to update my status, get tweets on home and usertimeline. But when I am trying to reply to a tweet (sent by userb), the reply is sent, but it is shown as a new tweet in userb twitter account not as reply to his earlier tweet.
What possible I might doing wrong.

Any help is appreciated


#2

I’m not sure as I’ve not used Spring Social for this, but the important thing is that the new Tweet is posted with the in_reply_to_status_id value set. There’s more on this in the statuses/update documentation.


#3

Haven’t tried this myself, but If you’re replying to tweet id 1234567890 for example:

StatusDetails statusDetails = new StatusDetails().setInReplyToStatusId(1234567890)
twitter.timelineOperations().updateStatus("@user this is a reply", statusDetails)

Should work.


#4

Hello Everyone,

@Andy, I had gone through the documentation and then only implemented but its not working.
@IgorBrigadir I am doing the same thing but there is difference in the api.
For reference:

This json , 745939481346244609 is the id of the tweet send by @abc which i am respoding in msg.

{"msg":"@abc Reply 1 to TC-13","inReplyToStatusId":745939481346244609}

This is the code

TweetData tweetData=new TweetData(msg.getMsg());
tweetData.inReplyToStatus(msg.getInReplyToStatusId());
Tweet tweet=twitter.timelineOperations().updateStatus(tweetData);

But this reply is sent as a new tweet to @abc and not as reply to his tweet.

I tried searching for twitter rest api for Java but only found Spring Social. Are there other alternatives to Spring Social?

Thanks & Regards,
Arpit U. Gadle


#5

Twitter4J is another option.


#6

Hi Andy,

I tried twitter4j but still the same result. Itried searching over the net no success. What wrong am I doing or is there anything which I missed out.

Thanks & Regards,
Arpit Gadle


#7

Maybe if you shared a code snippet that demonstrates the problem you are having, we would be able to advise.


#8

Hi,

Note: @davidsimpson227 is following @Value1stConnect, but @Value1stConnect is not following @davidsimpson227

This is one tweet recieved, for my @Value1stConnect from @davidsimpson227.

I am using “id”:“747729060416086016” while sending the reply to this tweet. The Json which I am sending to my restpi which in turns post this reply are given below

Tweet Recieved

    {
        "rateLimitStatus": null,
        "accessLevel": 0,
        "createdAt": 1467107474000,
        "id": 747729060416086016,
        "text": "@davidsimpson227 hello, how are you?",
        "source": "<a href=\"http://www.valuefirst.com\" rel=\"nofollow\">ValueFirstInsu</a>",
        "inReplyToStatusId": -1,
        "inReplyToUserId": 570573922,
        "favoriteCount": 0,
        "inReplyToScreenName": "davidsimpson227",
        "geoLocation": null,
        "place": null,
        "retweetCount": 0,
        "lang": "en",
        "retweetedStatus": null,
        "userMentionEntities": [
          {
            "start": 0,
            "end": 16,
            "name": "David Simpson",
            "screenName": "davidsimpson227",
            "id": 570573922,
            "text": "davidsimpson227"
          }
        ],
        "hashtagEntities": [],
        "mediaEntities": [],
        "extendedMediaEntities": [],
        "symbolEntities": [],
        "currentUserRetweetId": -1,
        "scopes": null,
        "user": {
          "rateLimitStatus": null,
          "accessLevel": 0,
          "id": 2905117489,
          "name": "Value First Insuranc",
          "screenName": "Value1stConnect",
          "location": "",
          "description": "",
          "descriptionURLEntities": [],
          "url": null,
          "followersCount": 3,
          "status": null,
          "profileBackgroundColor": "C0DEED",
          "profileTextColor": "333333",
          "profileLinkColor": "0084B4",
          "profileSidebarFillColor": "DDEEF6",
          "profileSidebarBorderColor": "C0DEED",
          "profileUseBackgroundImage": true,
          "showAllInlineMedia": false,
          "friendsCount": 2,
          "createdAt": 1416484627000,
          "favouritesCount": 0,
          "utcOffset": -25200,
          "timeZone": "Pacific Time (US & Canada)",
          "profileBackgroundImageUrlHttps": "https://abs.twimg.com/images/themes/theme1/bg.png",
          "profileBackgroundTiled": false,
          "lang": "en",
          "statusesCount": 37,
          "translator": false,
          "listedCount": 0,
          "withheldInCountries": null,
          "protected": false,
          "defaultProfile": true,
          "geoEnabled": false,
          "verified": false,
          "urlentity": {
            "start": 0,
            "end": 0,
            "url": "",
            "expandedURL": "",
            "displayURL": "",
            "text": ""
          },
          "contributorsEnabled": false,
          "profileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
          "biggerProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_bigger.png",
          "miniProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_mini.png",
          "profileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
          "defaultProfileImage": true,
          "profileBannerURL": null,
          "profileBannerIPadURL": null,
          "followRequestSent": false,
          "originalProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1.png",
          "biggerProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_bigger.png",
          "miniProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_mini.png",
          "originalProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1.png",
          "profileBackgroundImageURL": "http://abs.twimg.com/images/themes/theme1/bg.png",
          "profileBannerRetinaURL": null,
          "profileBannerIPadRetinaURL": null,
          "profileBannerMobileURL": null,
          "profileBannerMobileRetinaURL": null
        },
        "withheldInCountries": null,
        "quotedStatus": null,
        "quotedStatusId": -1,
        "contributors": [],
        "possiblySensitive": false,
        "retweet": false,
        "retweeted": false,
        "favorited": false,
        "truncated": false,
        "urlentities": [],
        "retweetedByMe": false
      }

Json Sent To Rest API

{
"msg":"@davidsimpson227 Very Good Morning David",
"inReplyToStatusId":"747729060416086016"
}

Rest API Method Using Twitter4J (Snippet)

@RequestMapping(value="/reply",method=RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Status> replyTweet(@RequestBody TweetMessage msg)
    	throws TwitterException
    	{
    		StatusUpdate tweetData=new StatusUpdate(msg.getMsg());
    		tweetData.setInReplyToStatusId(msg.getInReplyToStatusId());
    		
    		Status tweet=twitter.updateStatus(tweetData);
    		return new ResponseEntity<Status>(tweet,HttpStatus.OK);
    	}

The reply is sent, but the @davidsimpson227 has received it as tweet.
Response Received Againts Above Reply Sent

{
  "rateLimitStatus": null,
  "accessLevel": 3,
  "createdAt": 1467264137000,
  "id": 748386151556386818,
  "text": "@davidsimpson227 Very Good Morning David",
  "source": "<a href=\"http://www.valuefirst.com\" rel=\"nofollow\">ValueFirstInsu</a>",
  "inReplyToStatusId": -1,
  "inReplyToUserId": 570573922,
  "favoriteCount": 0,
  "inReplyToScreenName": "davidsimpson227",
  "geoLocation": null,
  "place": null,
  "retweetCount": 0,
  "lang": "en",
  "retweetedStatus": null,
  "userMentionEntities": [
    {
      "start": 0,
      "end": 16,
      "name": "David Simpson",
      "screenName": "davidsimpson227",
      "id": 570573922,
      "text": "davidsimpson227"
    }
  ],
  "hashtagEntities": [],
  "mediaEntities": [],
  "extendedMediaEntities": [],
  "symbolEntities": [],
  "currentUserRetweetId": -1,
  "scopes": null,
  "user": {
    "rateLimitStatus": null,
    "accessLevel": 0,
    "id": 2905117489,
    "name": "Value First Insuranc",
    "screenName": "Value1stConnect",
    "location": "",
    "description": "",
    "descriptionURLEntities": [],
    "url": null,
    "followersCount": 3,
    "status": null,
    "profileBackgroundColor": "C0DEED",
    "profileTextColor": "333333",
    "profileLinkColor": "0084B4",
    "profileSidebarFillColor": "DDEEF6",
    "profileSidebarBorderColor": "C0DEED",
    "profileUseBackgroundImage": true,
    "showAllInlineMedia": false,
    "friendsCount": 2,
    "createdAt": 1416484627000,
    "favouritesCount": 0,
    "utcOffset": -25200,
    "timeZone": "Pacific Time (US & Canada)",
    "profileBackgroundImageUrlHttps": "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profileBackgroundTiled": false,
    "lang": "en",
    "statusesCount": 38,
    "translator": false,
    "listedCount": 0,
    "withheldInCountries": null,
    "protected": false,
    "defaultProfile": true,
    "geoEnabled": false,
    "verified": false,
    "urlentity": {
      "start": 0,
      "end": 0,
      "url": "",
      "expandedURL": "",
      "displayURL": "",
      "text": ""
    },
    "contributorsEnabled": false,
    "profileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "biggerProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_bigger.png",
    "miniProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1_mini.png",
    "profileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
    "defaultProfileImage": true,
    "profileBannerURL": null,
    "profileBannerIPadURL": null,
    "followRequestSent": false,
    "originalProfileImageURL": "http://abs.twimg.com/sticky/default_profile_images/default_profile_1.png",
    "biggerProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_bigger.png",
    "miniProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1_mini.png",
    "originalProfileImageURLHttps": "https://abs.twimg.com/sticky/default_profile_images/default_profile_1.png",
    "profileBackgroundImageURL": "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profileBannerRetinaURL": null,
    "profileBannerIPadRetinaURL": null,
    "profileBannerMobileURL": null,
    "profileBannerMobileRetinaURL": null
  },
  "withheldInCountries": null,
  "quotedStatus": null,
  "quotedStatusId": -1,
  "contributors": [],
  "possiblySensitive": false,
  "retweet": false,
  "retweeted": false,
  "favorited": false,
  "truncated": false,
  "urlentities": [],
  "retweetedByMe": false
}

I hope this is will help you guys figure it out what mistake I am making, In the meanwhile, I am trying on my side, if got anything will share it with you.


#9

Hi @arpitgadle,

I noticed the same as you in the beginning and debugged myself a bit. This information might not be the information you want because I’m still using Spring Social Twitter Framework as in your initial question, but here are my observations:

General Setup:
UserA: Starts a tweet to UserB, UserA is following UserB
UserB: Receives the Tweet from UserA, UserB is not following UserA

  1. If I reply this tweet with userB via the twitter.com userA gets the reply as “in Conversation”
  2. If I reply this tweet with userB via Spring WebApp userA gets the reply as “in Conversation” (sometimes only after page reload, can’t figure out why)

Here is my code snippet that worked for me:

Tweet replyTweet = this.twitter.timelineOperations().updateStatus(this.buildReply(userBReplyString, userATweetObject.getId()));

private TweetData buildReply(String message, long tweetID) {
    return new TweetData(message).inReplyToStatus(tweetID);
}

Main difference is that I used getId() instead of getInReplyToStatusId(), so as far as I can think you used the wrong ID. I hope this helps you at least a little bit to make progress.

Best Regards
Dimitry Nagorny


#10

Hi Dimitry,

Thanks for your reply.
If you check my JSONs 747729060416086016 is the tweet Id which @UserB has received. And I am setting this 747729060416086016 in inReplyToStatusId when creating tweet data which is sent to @UserA.

For easy to understand, here is more self explanatory code

747729060416086016 tweet id

{
"msg":"@davidsimpson227 Very Good Morning David",
"tweetId":"747729060416086016"
}

@RequestMapping(value="/reply",method=RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Status> replyTweet(@RequestBody TweetMessage msg)
    	throws TwitterException
    	{
    		StatusUpdate tweetData=new StatusUpdate(msg.getMsg());
    		tweetData.setInReplyToStatusId(msg.getTweetId());
    		
    		Status tweet=twitter.updateStatus(tweetData);
    		return new ResponseEntity<Status>(tweet,HttpStatus.OK);
    	}