Results 1 to 4 of 4

Thread: TwitterTemplate Friendship Functionality

  1. #1
    Join Date
    Dec 2006
    Posts
    12

    Default TwitterTemplate Friendship Functionality

    Hi All

    Just wondering if there are plans to implement the friendship functionality in the TwitterTemplate. For example friendships/create, friendships/destroy etc.

    Also if I was to start adding that functionality to the TwitterTemplate, should I look into submitting patches back into Spring Social?

    garyj

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Gary,
    See http://blog.springsource.com/2010/12...ring-projects/ for contribution guidelines. We recently received a merge request for additions to FacebookTemplate and are reviewing that for integration as we speak.

    Keith
    Keith Donald
    Core Spring Development Team

  3. #3
    Join Date
    Dec 2006
    Posts
    12

    Default Started Work on the Follow/Unfollow Functionality

    Hi Guys

    So I'm working on the follow/unfollow functionality and am currently in the middle of testing the code. I used the apigee console to simulate a follow POST as follows:

    http://api.twitter.com/1/friendships/create.json?screen_name=oizik2

    and received the following response

    {
    "favourites_count" : 0,
    "friends_count" : 2,
    "profile_background_color" : "C0DEED",
    "url" : null,
    "profile_background_image_url" : "http://a3.twimg.com/a/1297708673/images/themes/theme1/bg.png",
    "description" : null,
    "screen_name" : "oizik2",
    "status": {
    "in_reply_to_status_id_str" : null,
    "in_reply_to_user_id" : null,
    "text" : "woohoo my twitter application is still working!!! ",
    "contributors" : null,
    "retweeted" : false,
    "in_reply_to_user_id_str" : null,
    "retweet_count" : 0,
    "geo" : null,
    "source" : <a href='http://www.ipeg.com.au' rel='nofollow'>iPeg - Test</a>,
    "created_at" : "Tue Feb 01 09:35:27 +0000 2011",
    "id_str" : "32371442398007296",
    "place" : null,
    "in_reply_to_status_id" : null,
    "coordinates" : null,
    "truncated" : false,
    "favorited" : false,
    "id" : 32371442398007296,
    "in_reply_to_screen_name" : null
    },
    "verified" : false,
    "location" : null,
    "listed_count" : 0,
    "time_zone" : null,
    "profile_text_color" : "333333",
    "lang" : "en",
    "notifications" : false,
    "created_at" : "Fri Jan 14 08:00:25 +0000 2011",
    "profile_sidebar_fill_color" : "DDEEF6",
    "id_str" : "238061111",
    "show_all_inline_media" : false,
    "geo_enabled" : false,
    "profile_background_tile" : false,
    "followers_count" : 1,
    "profile_link_color" : "0084B4",
    "protected" : false,
    "statuses_count" : 7,
    "profile_sidebar_border_color" : "C0DEED",
    "name" : "Gary Jarrel",
    "is_translator" : false,
    "contributors_enabled" : false,
    "following" : true,
    "id" : 238061111,
    "follow_request_sent" : false,
    "profile_use_background_image" : true,
    "utc_offset" : null,
    "profile_image_url" : "http://a2.twimg.com/sticky/default_profile_images/default_profile_1_normal.png"
    }


    This is one of my Twitter testing accounts.

    I then used the entire response in the follow.json file which and subsequently used it in my test case with the mockServer ... andRespond(withResponse(new ClassPathResource("follow.json", getClass()), responseHeaders));

    The problem is effectively with the returned JSON data and the line "source" : <a href='http://www.ipeg.com.au' rel='nofollow'>iPeg - Test</a>, notice how the URL is not quoted and this cause Jackson to fail with the following exception

    org.springframework.http.converter.HttpMessageNotR eadableException: Could not read JSON: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
    at [Source: java.io.ByteArrayInputStream@10aadc97; line: 18, column: 17]; nested exception is org.codehaus.jackson.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
    at [Source: java.io.ByteArrayInputStream@10aadc97; line: 18, column: 17]
    at org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter.readInternal(MappingJacks onHttpMessageConverter.java:138)
    at org.springframework.http.converter.AbstractHttpMes sageConverter.read(AbstractHttpMessageConverter.ja va:154)
    at org.springframework.web.client.HttpMessageConverte rExtractor.extractData(HttpMessageConverterExtract or.java:74)
    at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:619)
    at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:1)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:446)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:409)
    at org.springframework.web.client.RestTemplate.postFo rEntity(RestTemplate.java:313)
    at org.springframework.social.twitter.TwitterTemplate .follow(TwitterTemplate.java:142)
    at org.springframework.social.twitter.TwitterTemplate Test.follow(TwitterTemplateTest.java:138)
    .......


    When I manually put the quotes around the URL then it works fine, however with the actual Twitter response it fails on the < character.

    Is there a way to tell Jackson to treat this as a String perhaps, or add an exception to allow parsing such data?

    Or perhaps I should go to the Jackson mailing list?

    Cheers,

    Gary

  4. #4
    Join Date
    Dec 2006
    Posts
    12

    Default Solved

    Please ignore my post above, I was using the response from apigee console, when I used the Twurl console the response was formatted correctly.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •