#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0

    GET cross domain proxy to display in html


    Hello
    I am having a hell of a time grabbing a URL ttp://184.173.18.228/api/profile/1000/0/Adam.Adams that is XML when viewed in the browser - the idea is that when a user updates their profile (on another site) it will update ( also) on our site.. I have tried everything to get that url into php to echo on page - I was able to display the xml info on a page when the xml was local on my machine with jQuery but we need to use PHP ( I guess)
    Can anyone show me how to do this? using a cross domain proxy script (?) CURL? Im lost - how hard would it be for someone to grab that url and at least display one node? for me for example code? Im not a PHP guy but we need this feature on our site - thanks
    Rob
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    PHP Code:
    $xml = new SimpleXMLElement("http://that thing"0true); 
    should get you started.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    that has definitely taken me on the right path - thanks!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    Im really close but I get the same error no matter which code I try


    Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/5wTn3P on line 5

    Warning: SimpleXMLElement::__construct(): {"ProfileSections":[{"SectionType":"ContactCard","Sections":[{"ContentType":"Pro in /code/5wTn3P on line 5

    Warning: SimpleXMLElement::__construct(): ^ in /code/5wTn3P on line 5

    and the code being along these lines-

    Code:
    <?php // Load XML $url = "http://184.173.18.228/api/profile/1000/0/Adam.Adams"; $string = file_get_contents($url); $xml = new SimpleXMLElement($string);  // Get the entries $entries = $xml->entry;  foreach($entries as $e){     // Get each entriy's id     $id = $e->id;     // Get the attributes     // ID is in the "im" namespace     $attr = $id->attributes('im', TRUE);     // echo id     echo $attr['id'].'<br/>'; } ?>
    a few version of this btw

    Im getting the feeling that the API a dev guy gave me is bad

    any help is appreciated
    R
  8. #5
  9. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    The site does some sort of content type negotiation: your browser would rather see XML so it sends XML, but without that indication it sends JSON by default.

    So forget XML and use
    PHP Code:
    $json json_decode($string); 
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    very interesting - thanks - Ill give it a try today - you rock!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    can you point me to a page that has an example of decoding an api like my example? seems liek every example is using an array instead

    thanks a million

    R
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    json_decode decodes the response and turns it into an array. If you don't know the format of the array, use the var_dump function on it.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    I think I got it! thsi code shoots output - the output Ive been waiting for - any idea how to slap it onto a page that I can style? - it outputs what looks like to me an array - I need that array into something I can format
    Code:
    <?php     $url="http://184.173.18.228/api/profile/1000/0/Adam.Adams";     $json = file_get_contents($url,0,null,null);     $json_output = json_decode($json);      echo '<pre>';       print_r("query results:");       print_r($json_output);      '</pre>';     foreach ( $json_output->data->items as $data ){     echo "{$data->id}";     echo "{$data->title}";     }     ?>
    thanks for help in advance

    Rob
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    7
    Rep Power
    0
    thanks! var dump - yeah, been seeing that

    if you can see this page http://callison.netau.net/proxy4.php that is what I managed to produce

    so I can see the array ( that is an array correct?)

    thanks for you help


    R

IMN logo majestic logo threadwatch logo seochat tools logo