Announcement Announcement Module
Collapse
No announcement yet.
Accessing a feed - problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing a feed - problem

    Hi,
    Im trying to access someones public feed so that the List of posts returned gives me an inkling of what fields to put in my LinkedMultiValueMap which I will need to publish my own feed. (incidently Im trying to publish a single post with multiple text and lnks in it)

    anyway
    Ive got a reference to a facebook template but when I do this...

    List<Post> posts = facebookTemplate.feedOperations().getFeed("1929286 8552");

    I get this exception..

    Exception in thread "main" org.springframework.web.client.ResourceAccessExcep tion: I/O error: (was java.lang.NullPointerException) (through reference chain: org.springframework.social.facebook.api.LinkPost["comments"]); nested exception is org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.springframework.social.facebook.api.LinkPost["comments"])
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:453)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:415)
    at org.springframework.web.client.RestTemplate.getFor Object(RestTemplate.java:213)
    at org.springframework.social.facebook.api.impl.Faceb ookTemplate.fetchConnections(FacebookTemplate.java :180)
    at org.springframework.social.facebook.api.impl.FeedT emplate.getFeed(FeedTemplate.java:43)

  • #2
    Which version of Spring Social are you doing this with? I just tried it with the latest snapshot build and it gave me several posts for 19292868552 (which happens to be the Facebook Platform page) with no problems.

    There were some issues in earlier versions of Spring Social that resembled what you show, but it was fixed before RC1. Try out RC1 (or the latest snapshot build) and this problem should go away. If not, let me know and I'll look a bit deeper to see if there's something else going on.

    Regarding your attempt to publish a single post with multiple text/links in it...I suppose the "multiple" part of that is what makes this more interesting than simply calling updateStatus() or postLink(). If you look at the postLink() method in FeedTemplate (https://github.com/SpringSource/spri...dTemplate.java), you'll get some idea of what fields can go into the request. I'm not sure about posting multiple links in a single post, though...I just tried putting multiple links in for the "links" field:

    Code:
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    map.add("link", "http://www.springsource.org");
    map.add("link", "http://www.habuma.com");
    map.add("link", "http://www.twitter.com");
    map.set("name", "Some links for you");
    map.set("caption", "Some links for you");
    map.set("description", "Some links for you");
    map.set("message", "Some links for you");
    String publish = fb.publish("me", "feed", map);
    And Facebook only kept the last one (http://www.twitter.com). I'm not sure if it's possible to post multiple links in a single post. I'd be interested to know if you have different results.
    Last edited by habuma; Jul 7th, 2011, 03:50 PM.

    Comment


    • #3
      Posting feed with multiple links

      It's possible with js api.
      Code:
      {
                              "message":'',
                              "link":''+webUrl,
                              "picture":mediaUrl,
                              "name": fbName,
                              "caption": fbCaption,
                              "description":fbDescription,
                              "privacy":"EVERYONE",
                              "actions": [{ "name": 'www.example.com', "link": 'http://www.example.com/' },{ "name": 'www.example1.com', "link": 'http://www.example1.com/' }]
      
                     }
      I don't know how to put links to actions. What should be there ?

      MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
      map.add("actions", "what should be there");

      Comment


      • #4
        interesting, surely if this can be done in JS then it can be done through the Spring binding

        im trying this but the damn thing still wont work:

        MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>();
        jsonArray = new JSONArray();
        jsonObject = new JSONObject();
        jsonObject.put("name", "text1");
        jsonObject.put("link", "www.bla.com");
        jsonArray.put(jsonObject);

        jsonObject = new JSONObject();
        jsonObject.put("name", "text2");
        jsonObject.put("link", "www.foo.com/bla");
        jsonArray.put(jsonObject);


        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
        map.add("link", "http://www.google.com");

        map.set("name", "name");
        map.set("caption", "xxx");
        map.set("description", "yyy");
        map.set("message", "zzzz");
        map.set("actions", jsonArray.toString());


        facebookTemplate.publish("me", "feed", map);
        Last edited by emmettwalsh; Jul 12th, 2011, 11:49 AM. Reason: submitted by accident

        Comment


        • #5
          There are two matters here: (1) Can it be done via Spring Social's Facebook API binding? and (2) Can it be done through Facebook's Graph API?

          I'm not certain if it can be done through the Spring Social API binding as it is today. I say that I'm not certain, rather than given a definitive answer because I'm not sure of how to do it through Facebook's Graph API.

          I've tried several things with the Graph API (using both their API explorer--https://developers.facebook.com/tools/explorer) and just using the curl command line tool. So far I've had no luck posting multiple links or multiple action links. My last attempt was to POST (using curl) a JSON file containing something like what was shown above for the JS API. The Graph API accepted it and created a new post, but it did not have the action links that were in the JSON. I've got a few more ideas to try out, but at this point I'm not sure if/how it can be done through the Graph API.

          It's important to realize that FB's Graph API has some limits and can't necessarily do everything that the JS API or even their older REST API can do. FB has been taking steps to make the Graph API more capable, but it's possible that this is one of those things that the Graph API can't do. If it *is* possible through the Graph API, let me know how you did it and create an improvement issue in JIRA and we'll look into enabling Spring Social's API binding to do it.

          Comment


          • #6
            After a few more tries I was able to POST a single action link like this:

            Code:
            MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();		
            data.set("link", "http://www.habuma.com");
            data.set("actions", "{'name':'SpringSource','link':'http://www.springsource.com'}");
            String id = fb.publish("me", "feed", data);
            Notice the "actions" field has a JSON dictionary with the name and the link. If I try this, however:

            Code:
            MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();		
            data.set("link", "http://www.habuma.com");
            data.set("actions", "[{'name':'SpringSource','link':'http://www.springsource.com'},{'name':'Google','link':'http://www.google.com'}]");
            String id = fb.publish("me", "feed", data);
            Then it won't work with this error body:

            Code:
            {
              error: {
                type: "OAuthException",
                message: "(#100) actions should be a JSON-encoded dictionary with "name" and "link" keys",
              }
            }
            Note that if I use the square brackets with a single entry it *will* work, but adding a 2nd link it gives the error. So, it seems that you can post a link with a single action link (which is shown right next to the "Like" and "Comment" link in the user's feed). But multiple actions do not seem to be possible.

            Comment

            Working...
            X