Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String could not be parsed as XML #46

Closed
jeffsgq opened this issue Jan 6, 2015 · 6 comments
Closed

String could not be parsed as XML #46

jeffsgq opened this issue Jan 6, 2015 · 6 comments

Comments

@jeffsgq
Copy link

jeffsgq commented Jan 6, 2015

hi all
l'm a new comer for php. l want to get data from google spread sheet , l use the php-google-spreadsheet-client, now l got some trouble.

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in....
someone can help?

@asimlqt
Copy link
Owner

asimlqt commented Jan 6, 2015

Hi,

Can you paste the code you're using and explain how you're generating the access token.

Thanks

@thephm
Copy link

thephm commented Jan 11, 2015

I have the same issue. Up until today I was using the library from Nov 3 and now downloaded current version. What worked before no longer works

// obtain an access token from Google
$obj_token = json_decode( $Google->client->getAccessToken() ); // $Google is an instance of a class I created to encapsulate authentication
$accessToken = $obj_token->access_token;

$serviceRequest = new DefaultServiceRequest( $accessToken );
ServiceRequestFactory::setInstance( $serviceRequest );

$spreadsheetService = new SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();

The exception:

( ! ) Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in www\php-google-spreadsheet-client\src\Google\Spreadsheet\SpreadsheetFeed.php on line 45
( ! ) Exception: String could not be parsed as XML in www\php-google-spreadsheet-client\src\Google\Spreadsheet\SpreadsheetFeed.php on line 45
Call Stack

Time Memory Function Location

1 0.0040 414208 {main}( ) ..\rosterexport.php:0
2 2.7495 17385320 Google->createSheetFile( ) ..\rosterexport.php:411
3 4.0874 17725688 Google\Spreadsheet\SpreadsheetService->getSpreadsheets( ) ..\google.php:184
4 4.1483 17726784 Google\Spreadsheet\SpreadsheetFeed->__construct( ) ..\SpreadsheetService.php:39
5 4.1483 17727008 __construct ( ) ..\SpreadsheetFeed.php:45

@kvasko
Copy link

kvasko commented Jan 20, 2015

Dear All,

With the help of asimlqt I was able to create an update script for my Google Spreadsheet. Unfortunately during the update/insert process I get many times the same error as well what you described above (and in the Subject) -> Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /google-api-php-client/src/Google/Spreadsheet/CellFeed.php:137 Stack trace: #0 /google-api-php-client/src/Google/Spreadsheet/CellFeed.php(137): SimpleXMLElement->__construct('') #1 /wwwroot/html_parser_test.php(337): Google\Spreadsheet\CellFeed->updateBatch(Object(Google\Spreadsheet\Batch\BatchRequest)) #2 {main} thrown in /google-api-php-client/src/Google/Spreadsheet/CellFeed.php on line 137.....

I checked many forums and possible solutions BUT till now none of them helped to solve this issue. I use the following code to create the AccessToken:

$client = new Google_Client();
$client->setApplicationName('xxx App');
$client->setClientId($client_id);

$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://spreadsheets.google.com/feeds'),
file_get_contents($key_file_location)
);

$client->setAssertionCredentials($cred);

if($client->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}

$obj_token = json_decode($client->getAccessToken());
$accessToken = $obj_token->access_token;

$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);

//Working with the SpreadSheet
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();

Any ideas how can I solve this issue? I appreciate all helps because I have to solve this problem asap.

Thanks for your help in advance!

BR,
Krisztián

@zak905
Copy link

zak905 commented Jan 28, 2015

I have the same issue with : $spreadsheetFeed = $spreadsheetService->getSpreadsheets();
I could obtain an access token successfully, but not the list of spreadsheets. Apparently, the $xml in the class SpreadsheetFeed.php is empty. If you try with the following modification in the constructor :

public function __construct($xml)
{
if(!empty($xml) ){
$this->xml = new SimpleXMLElement($xml);

            $spreadsheets = array();
            foreach ($this->xml->entry as $entry) {
                $spreadsheets[] = new Spreadsheet($entry);
            }
            parent::__construct($spreadsheets);

    }
    else {
        echo "empty XML <br>";
    }
}

It always displays "Empty XML". I think the request is not working properly.

Any suggestions ?

Regards,
Zakaria

@dustfeather
Copy link

Same here:
$client = new Google_Client();
$client->setApplicationName("{app_name}");
$client->setClientId('{client_id}');
$cred = new Google_Auth_AssertionCredentials(
'{client_email}',
array('https://www.googleapis.com/auth/drive', 'https://spreadsheets.google.com/feeds'),
file_get_contents(Yii::app()->basePath . 'key.p12')
);
$client->setAssertionCredentials($cred);
$client->getAuth()->refreshTokenWithAssertion($cred);
$obj_token = json_decode($client->getAccessToken());
$accessToken = $obj_token->access_token;
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheet = $spreadsheetService->getSpreadsheetById('{document_key}');

[code] => 500
[type] => Exception
[errorCode] => 0
[message] => String could not be parsed as XML

@asimlqt
Copy link
Owner

asimlqt commented Mar 17, 2016

I'm going to add improved error handling in the next version.

@asimlqt asimlqt closed this as completed Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants