Jump to:

23453 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Cant get RestfulService to work with ->Request()

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1651 Views
  • otherjohn
    Avatar
    Community Member
    125 Posts

    Cant get RestfulService to work with ->Request() Link to this post

    Hi all, Since RestfulService::Connect has been depreciated, can someone point out what I am doing wrong here?

    Here is my code, I get no response. But when I used ->Connect() instead of ->Request(), it worked.
    Can someone point out what I am missing?
    The $url = a twitter user feed.

    function doCall($url = null, $requireAuth = false,$params = null){
          try{
             
             $twitter = new RestfulService( $url );
             
             
             if($params)
                $twitter->setQueryString($params);
             
             $conn = $twitter->request();
             
             $xml = @simplexml_load_string($conn);
             
          
             if($xml == false){
                return false;
             }else{ return $xml;}
          }
          catch(Exception $e){
             
             return false;
          }
       }

  • otherjohn
    Avatar
    Community Member
    125 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    This line is not returning anything?
             $xml = @simplexml_load_string($conn);
    Any Idea? It seems that $conn returns from -->Request as an obj and not a string.

  • otherjohn
    Avatar
    Community Member
    125 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    adding $conn = $conn->simpleXML(); seems to fix it.

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    if there is'nt a RestFull service, How is possible to communicate with SS from remote service?

  • Dynamic
    Avatar
    Community Member
    16 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    Hi otherjohn,

    Running into the same problem, trying out 2.4 stable and modifying the old Twitter module.

    adding "$conn = $conn->simpleXML();" didn't do it for me, the "$xml = @simplexml_load_string($conn);" still returns nothing.

    Could you repost your final code? Hoping I can figure something out for this.

    Thanks!

  • ram
    Avatar
    Community Member
    19 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    Hi

    SS 2.4.0 Since RestfulService::Connect has been depreciated, so we replace to ->request('')->getBody();

    eg.,
          $newsdet = new RestfulService($url,"3600");
          $conn = $newsdet->request('')->getBody();
          $msgs = $newsdet->getValues($conn);

    Hope its works

    Regards,
    Ram
    http://www.agriya.com,http://www.rayzz.net, http://www.anova.tv, http://www.isocial.in, http://www.markit.me

  • dayer
    Avatar
    Community Member
    11 Posts

    Re: Cant get RestfulService to work with ->Request() Link to this post

    Hi,

    but if I need obtain values and attributes, have I to use getValues and getAttributes? Because by the moment I have to use simplexml_load_string and after create a DataObjectSet and fill it with a values and attributes array.

    Regards.

    1651 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.