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 #56

Open
zak905 opened this issue Feb 2, 2015 · 9 comments
Open

String could not be parsed as XML #56

zak905 opened this issue Feb 2, 2015 · 9 comments

Comments

@zak905
Copy link

zak905 commented Feb 2, 2015

Hello,

I am new to php, but I have used Google Spreadsheets API in Java and I understand how it works. I have an issue with this simple example that tries to get the list of Spreadsheets. and print their names. My Code:

setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->addScope("https://spreadsheets.google.com/feeds"); ``` if (isset($_REQUEST['code']) ) { $code = $_REQUEST['code']; $response = $client->authenticate($code); $_SESSION['access_token'] = $client->getAccessToken(); } if (isset($_SESSION['access_token'])) { $code = $_SESSION['access_token']; $client->setAccessToken($code); } else{ $authUrl = $client->createAuthUrl(); echo " Authenticate "; echo " "; try{ $accessToken= $client->getAccessToken(); $_SESSION['access_token'] = $accessToken; }catch(Exception $e){ echo 'Message1: ' .$e->getMessage(); } } $code = $_SESSION['access_token']; $obj = json_decode($code, true); $access_token_code = $obj['access_token']; $this->serviceRequest = new DefaultServiceRequest($access_token_code); ServiceRequestFactory::setInstance($this->serviceRequest); } function getSpreadsheetList(){ $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); $spreadsheetFeed = $spreadsheetService->getSpreadsheets(); foreach($spreadsheetFeed->xml->entry as $spreadsheetName){ echo "here
"; echo "$spreadsheetName
"; } } ``` } try{ $spreadsheetimporterService = new SpreadsheetImporter(); $spreadsheetimporterService->getSpreadsheetList(); } catch(Exception $e){ echo 'Message2: ' .$e->getMessage(); } However, I get the following exception: String could not be parsed as XML. Anybody who has a hint or suggestions for solving this issue would be much appreciated. Thanks Regards, Zakaria
@asimlqt
Copy link
Owner

asimlqt commented Feb 5, 2015

Hi,

I'm not sure your way of generating the token is correct. The method you seem to be using is for installed applications and php applications are generally classed as "Web Applications". This is the only method i've used and tested.

Can you please clone the following project and try to generate an access token using the method described in the README. if you still have trouble then let me know.

https://github.com/asimlqt/php-google-oauth

@zak905
Copy link
Author

zak905 commented Feb 8, 2015

Thanks for your feedback. Your Oauth generation works fine.

I discovered the root of the issue, which has nothing to do with OAuth but with SSL.

I added the following code to execute() function in DefaultServiceRequest.php:

$ret=curl_exec($ch);

if(ret === false)
{
    echo "Error Number:".curl_errno($ch)."<br>";
    echo "Error String:".curl_error($ch);
}

and I got the following Error message: SSL certificate problem, verify that the CA cert is OK.

And the turnaround is by setting this option to false: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) ; during initialization.

I am not sure if it is valid for Ubuntu as well, but in my case, (on windows), It solved the issue.

@kanafghan
Copy link

I did the same as @zak905 described above and it worked fine for me. I'm on Windows 8.1 using the Chrome browser.

@SimonEast
Copy link

Yes, if you're developing on Windows machines, you usually need to disable CURLOPT_SSL_VERIFYPEER. I did this by editing initRequest() inside /vendor/asimlqt/php-google-spreadsheet-client/src/Google/Spreadsheet/DefaultServiceRequest.php.

@mTorres
Copy link

mTorres commented May 7, 2015

You shouln't disable SSL verification as you are opening yourself to MIM attacks. Instead just download the CA bundle from the cURL guys and update your php.ini:

[CURL]
curl.cainfo = "path/to/cacert.pem"

BTW, I've also made a PR to check the returned value from curl_exec because I've found myself with the same problem.

@sagark1510
Copy link

@zak905 Got the same issue and you are right CURLOPT_SSL_VERIFYPEER = False is the solution.

@ronakprogrammer
Copy link

@asimlqt I tried with setting "CURLOPT_SSL_VERIFYPEER = false" but still for some case it throws error.sometimes work and sometimes suddenly throws error there is not any issue with access token also because I am regenerating the token when making calls to spreadsheet api.Its weird to see such kind of result that sometimes work and sometimes don't work and throws error like this "String could not be parsed as XML"

Can you tell me whats wrong there?

@asimlqt
Copy link
Owner

asimlqt commented Apr 23, 2016

@ronakprogrammer

Yes that is odd.

Are you using windows? Also can you provide the full code you are using?

@Jiys
Copy link

Jiys commented Dec 5, 2017

@asimlqt I had the exact same problem as @ronakprogrammer mentioned above, did you figure it out? Please Help!

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

8 participants