socialmatrix Posted September 18, 2008 Share Posted September 18, 2008 Hello, I am trying to aggregate content from two different web services in my program. One service is here: http://149.169.176.63/xampp/atit//asap!/index.php?method=printnumbers. it print 1 through 5 in XML, output looks like this <numbers> <number>1</number> <number>2</number> <number>3</number> <number>4</number> <number>5</number> </numbers> Another service is here (will ask you to log into facebook, if you try): http://149.169.176.63/xampp/atit//asap!/index.php?method=getFBNhood. This service returns following output (your facebook buddies in XML list): <friends> <friend>513947</friend> <friend>1203206</friend> <friend>1304215</friend> <friend>1914531</friend> <friend>2230339</friend> </friends> Now, I need to aggregate these services such that they output as following <numbers> <number>1</number> <number>2</number> <number>3</number> <number>4</number> <number>5</number> </numbers> <friends> <friend>513947</friend> <friend>1203206</friend> <friend>1304215</friend> <friend>1914531</friend> <friend>2230339</friend> </friends> So being naive about this, I tried something like following code. However, it doesn't work <?php $a = file_get_contents("http://149.169.176.63/xampp/atit/ASAP!/?method=printnumbers"); $a .= file_get_contents("http://149.169.176.63/xampp/atit//call/index.php?primitive=neighbourhood&socialNetwork=facebook"); echo $a; ?> first service is called and displayed. However, right after that another HTTP call is made that print values ONLY from second service. How do I get desired output? i.e. content from both the services together? Thank You very much, Socialmatrix Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/ Share on other sites More sharing options...
jamesbrauman Posted September 18, 2008 Share Posted September 18, 2008 <?php $a = file_get_contents("http://149.169.176.63/xampp/atit/ASAP!/?method=printnumbers"); $a = $a."\r\n".file_get_contents("http://149.169.176.63/xampp/atit//call/index.php?primitive=neighbourhood&socialNetwork=facebook"); echo $a; ?> Untested, don't know if that would work, give it a crack though. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644521 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Thank you jamesbrauman, However, it didn't help It does the same thing as what my code was doing. Here's the link where I have the script suggested by jamesbrauman: http://tinyurl.com/socialmetric/test.php Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644548 Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 not sure if im way off but i know with mysql i need to name a second call different try playing with that idea <?php $a = file_get_contents("http://149.169.176.63/xampp/atit/ASAP!/?method=printnumbers"); $b= file_get_contents("http://149.169.176.63/xampp/atit//call/index.php?primitive=neighbourhood&socialNetwork=facebook"); echo $a; echo $b; ?> Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644599 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 Given that you're loading two sets of XML data, it's entirely possible that there's two XML declarations, which is bound to give you problems. Try pasting the source of the generated file. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644606 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks Ben , BY XML declarations do you mean: header ("Content-Type:text/xml");? Yeah that is done twice, once for each service. pasting the source of the generated file is not an option. I HAVE TO call it to be able to aggregate both. However, I am allowed to make modification at the service. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644794 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 No, my declaration i mean <?xml version=... And I think you misunderstand me. What I was asking to see is the output (and specifically the source) of the above script. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644819 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Oh extremely sorry, echo "<?xml version='1.0' encoding='UTF-8'?>"; is indeed done twice This is the script: <?php function getFaceBookNeighbourhoodCall($request) //function that gets list of your friends in facebook { require_once 'D:\dev_tools\xampp-win32-1.6.4\xampp\htdocs\xampp\atit\facebook-platform\facebook-platform\php\facebook.php'; $appapikey = 'myAppKey'; $appsecret = 'mySecretKey'; $facebook = new Facebook($appapikey, $appsecret); $user_id = $facebook->require_login(); $friends = $facebook->api_client->friends_get(); //$friends = array_slice($friends, 0, 25); ?> <?php header('Content-Type: text/xml'); echo "<?xml version='1.0' encoding='UTF-8'?>"; $retval = "<friends>"; foreach ($friends as $friend) { $retval .= "<friend>"; $retval .= $friend; $retval .= "</friend>"; } $retval .= "</friends>"; echo "$retval"; } function printNumbersCall($request) //function that print 1 through 5 { ?> <?php header('Content-Type: text/xml'); echo "<?xml version='1.0' encoding='UTF-8'?>"; $retval = "<numbers>"; $i=1; while($i<=5) { $retval .= "<number>" . $i . "</number>"; $i++; } $retval .= "</numbers>"; echo "$retval"; } ?> getFBNhood or printNumber function is called based on the RESTful URL Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644866 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 echo "<?xml version='1.0' encoding='UTF-8'?>"; is indeed done twice Well that is at least part of your problem then. That declaration should only appear once. You should only be setting the content type once too. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644870 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks a lot Ben, Let me see if there is any way for me to get away with only one set of XML declaration and content type. Atit Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644873 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Actually, in future I am going to be aggregating data from other APIs not developed by me. With that in mind, I won't be able to restrict only one set of XML declaration and content type. Can you suggest me any other alternative? one option I just thought of is, may be I can call these services, store data in Relational Database and write an SQL query to retrieve data. At last, emit these data as XML. However, this sounds counter intuitive, can you please comment on any complexity with this solution? Thank You, Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644893 Share on other sites More sharing options...
GingerRobot Posted September 18, 2008 Share Posted September 18, 2008 Personally i'd be looking to read the contents into a string and strip out the xml declarations before echoing the rest of the content. Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644898 Share on other sites More sharing options...
socialmatrix Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks again Ben, Now that you have been helping me so much. Can you possibly point me "How to strip out the xml declarations"? If you know on the top of your head? Thanks Link to comment https://forums.phpfreaks.com/topic/124764-aggregating-contents/#findComment-644910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.