Jump to content

aggregating contents


socialmatrix

Recommended Posts

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 :(

 

 

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.