I'm trying to write a very simple bit of php that parses some XML data from an API call.

I've got the xml parsing down (not real details):

   $myevents = simplexml_load_file("https://www.eiseverywhere.com/api/v2/ereg/getEvent.xml?accesstoken=34673483734734734&eventid=3483483");    echo $myevents->location[0]->name;

My issue is with the authentication for the API call the api (like most) requires each call uses an access token created on the fly using this (not real data):

   $mynumber = simplexml_load_file("https://www.eiseverywhere.com/api/v2/global/authorize.xml?accountid=7834&key=214lkh21lkh412kh212");

This returns the access token as xml, I want to set that token as a variable for use in the first call, but when I use the following, it doesn't work.

<?php
$mynumber = simplexml_load_file("https://www.eiseverywhere.com/api/v2/global/authorize.xml?accountid=6236&key=okil3h613oj2o3ji5h2oih");

echo $mynumber->accesstoken;


$myevents = simplexml_load_file("https://www.eiseverywhere.com/api/v2/ereg/getEvent.xml?accesstoken=$mynumber&eventid=124124");

echo $myevents->location[0]->name;

?>

Sorry if this seems totally wrong, this is my first day with PHP!

有帮助吗?

解决方案

Looking at your code, you are using the xml object as the access token, not the actual string token.

<?php 
// change this line
$myevents = simplexml_load_file("https://www.eiseverywhere.com/api/v2/ereg/getEvent.xml?accesstoken=$mynumber&eventid=124124");

// to this    
$token = $mynumber->accesstoken;
$myevents = simplexml_load_file("https://www.eiseverywhere.com/api/v2/ereg/getEvent.xml?accesstoken={$token}&eventid=124124");
?>

Welcome to PHP! :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top