Mancent Posted October 3, 2011 Share Posted October 3, 2011 My question is can you write a php file that loads a http://URL from off site, then Write the off site array to a xml file on your own domain? Example facebooks https://graph.facebook.com/btaylor loads the users basic Information into a array. { "id": "220439", "name": "Bret Taylor", "first_name": "Bret", "last_name": "Taylor", "link": "http://www.facebook.com/btaylor", "username": "btaylor", "gender": "male", "locale": "en_US" } So can php pull that http://URL and see that its a array, then convert it to a xml file // Get User ID $user = $facebook->getUser(); // We may or may not have this data based on whether the user is logged in. // // If we have a $user id here, it means we know the user is logged into // Facebook, but we don't know if the access token is valid. An access // token is invalid if the user logged out of Facebook. if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } // Login or logout url will be needed depending on current user state. if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } $profile = array ($user_profile); $xml = new SimpleXMLElement('<root/>'); arrayToXML( $xml, $profile ); echo $xml->asXML(); function arrayToXML( SimpleXMLElement &$xml, $array ) { foreach( $array as $name => $value ) { if( !is_array($value) ) $xml->addChild( $name, $value ); else { $child = $xml->addChild( $name ); arrayToXML( $child, $value ); } } } ?> But when i use this and convert it over to xml, the XML file changes The array has so much more in it, then I need all I want is the basics. Like the link above. Quote Link to comment https://forums.phpfreaks.com/topic/248306-it-is-possible/ Share on other sites More sharing options...
Mancent Posted October 3, 2011 Author Share Posted October 3, 2011 You see if i fill out Facebook and add a lot of information it pulls all the information, How can I only pull the information I want, is there a way to remove some of the output? This is full all and i still think the file can load much much more, if you like say 100 teams the xml file would load different again, and it would be so much larger, same for music schools and anything else you have on your facebook Information page. <?xml version="1.0"?> <root><0><id>100001957015772</id><name>Clarity Understanding</name><first_name>Clarity</first_name><last_name>Understanding</last_name><link>http://www.facebook.com/clarity.understanding</link><username>clarity.understanding</username><hometown><id>112890068728512</id><name>Heavenly Hills, California</name></hometown><location><id>112890068728512</id><name>Heavenly Hills, California</name></location><work><0><employer><id>227528230633747</id><name>CEO Clarity Dreams</name></employer><location><id>106274566070183</id><name>Winchester, Kentucky</name></location><position><id>143257402365425</id><name>Web Developer</name></position><description>All that I learned from the first day I got a PC, until now, lets see what I can do.</description><start_date>1995-01</start_date></0></work><sports><0><id>181901631820268</id><name>NASCAR</name></0><1><id>104019549633137</id><name>Football</name></1></sports><favorite_teams><0><id>126315184089478</id><name>Jeff gordan</name></0><1><id>110264072330485</id><name>Colts football</name></1></favorite_teams><favorite_athletes><0><id>109563725729117</id><name>Peyton Manning</name></0></favorite_athletes><inspirational_people><0><id>183034171772476</id><name>My God My Lord My Jesus My Son</name></0></inspirational_people><education><0><school><id>115250758498809</id><name>WCHS</name></school><year><id>131821060195210</id><name>1997</name></year><type>High School</type></0><1><school><id>155092571249950</id><name>The Book Of God Is My Teacher.</name></school><year><id>138792749476094</id><name>1978</name></year><concentration><0><id>193730633989737</id><name>The Word of God</name></0></concentration><type>College</type></1></education><gender>male</gender><email>[email protected]</email><timezone>-4</timezone><locale>en_US</locale><languages><0><id>113301478683221</id><name>American English</name></0><1><id>104073086294557</id><name>Biblical Hebrew</name></1><2><id>112307105452806</id><name>Ancient Greek</name></2></languages><verified>1</verified><updated_time>2011-10-03T00:07:59+0000</updated_time></0></root> Here is my problem, as i log into another Facebook account and I read the xml file again, it is different. <?xml version="1.0"?> <root><0><id>100002678639121</id><name>Rob Puckett</name><first_name>Rob</first_name><last_name>Puckett</last_name><link>http://www.facebook.com/profile.php?id=100002678639121</link><gender>male</gender><email>[email protected]</email><timezone>-4</timezone><locale>en_US</locale><verified>1</verified><updated_time>2011-09-27T21:15:24+0000</updated_time></0></root> You see it only gets some of the information I have set on my facebook, so what can I do to make the array only get the ID, FIRST NAME LAST NAME EMAIL GENDER AND ANY OTHER I WANT? But at my own request? Would any one know? Quote Link to comment https://forums.phpfreaks.com/topic/248306-it-is-possible/#findComment-1275080 Share on other sites More sharing options...
Mancent Posted October 3, 2011 Author Share Posted October 3, 2011 NVM, It was a simple fix All you have to do is define the fields you want in the api $user_profile = $facebook->api('/me?fields=id,name'); And so on get what ever you want and need.. so simple. Quote Link to comment https://forums.phpfreaks.com/topic/248306-it-is-possible/#findComment-1275114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.