Jump to content

Can any one help me solve this problem.


Mancent

Recommended Posts

Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]: unterminated entity reference limit=50&method=GET&access_token=AAACd5Mcn7VQBAKaupEZCocujRuoBzzWeZCj945ZApHEsv5BZAxZCJfS62cSSz4txlZBUZAec03GcjpHdk0NTotnglt2ZB41GzzeYl8xqIZBmsvlS6UZAoHZB1A4&offset=50 in /home/content/71/8432771/html/facebook/get/friends.php on line 62

 

 

<?php
/**
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

require '../../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'APPID',
  'secret' => 'SECRET',
));

// 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/friends?fields=id,name,first_name,last_name,picture&limit=50');
  } 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 );   <----------------------------------------------LINE 64
		arrayToXML( $child, $value );
	}
}
}

?>

 

 

Here is the array

 

{
   "data": [
      {
         "name": "Pauline Latty",
         "id": "312293"
      },
      {
         "name": "Noah Ethan Schinasi",
         "id": "55101245"
      },
      {
         "name": "Luis Guerrero",
         "id": "194803212"
      },
      {
         "name": "Nakia Johnson",
         "id": "500350828"
      },
      {
         "name": "Bethany Vallerie",
         "id": "502062429"
      },
      {
         "name": "Caroline Franks",
         "id": "505331027"
      },
      {
         "name": "Andrew Shivers",
         "id": "505749817"
      },
      {
         "name": "Sandra G Garcia",
         "id": "508006303"
      },
      {
         "name": "Catherine Davis",
         "id": "511006416"
      },
      {
         "name": "Marc Watson",
         "id": "511201074"
      },
      {
         "name": "Laura Clarke",
         "id": "513653820"
      },
      {
         "name": "Amanda Rice",
         "id": "514062403"
      },
      {
         "name": "Scott Alan Buss",
         "id": "514197867"
      },
      {
         "name": "Evangelist Josephus",
         "id": "515837621"
      },
      {
         "name": "Chet Fontenot",
         "id": "516199085"
      },
      {
         "name": "Sharon Howard",
         "id": "516580144"
      },
      {
         "name": "Chatt Franco",
         "id": "517211511"
      },
      {
         "name": "Lydgia Vanessa Staples",
         "id": "518094760"
      },
      {
         "name": "Corry Bell",
         "id": "521043483"
      },
      {
         "name": "Lessie Tyson",
         "id": "521855454"
      },
      {
         "name": "Jawahar Peter",
         "id": "523159934"
      },
      {
         "name": "Sheena Shiko",
         "id": "523461577"
      },
      {
         "name": "Pat Larry Thomas",
         "id": "523555768"
      },
      {
         "name": "Oyenuga Kunle Johnson Matthew",
         "id": "524263978"
      },
      {
         "name": "Angela Whitten",
         "id": "524631356"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/me/friends?limit=25&access_token=2227470867|2.AQAMMvJya05xkLhR.3600.1318057200.0-100001957015772|IUAhNlekyalf7sxy-OjdJd7KCwo&offset=25"
   }
}

 

its that paging, I can not seem to get that to work yet.

 

Link to comment
Share on other sites

You need to encode the string before sending it to simpleXML.

 

The question mark (?) is what is causing it to barf.  I would suggest the work around.

//instead of:
$xml->addchild('element',$str);
//do
$xml->element = $str;

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.