6 messages in com.googlegroups.google-picasa-data-apiRe: Detecting feed error messages in PHP| From | Sent On | Attachments |
|---|---|---|
| Cameron Hinkle | 18 Mar 2008 09:00 | |
| Jeff Fisher (Google) | 18 Mar 2008 10:16 | |
| Cameron Hinkle | 18 Mar 2008 10:46 | |
| Jeff Fisher (Google) | 18 Mar 2008 14:52 | |
| Cameron Hinkle | 18 Mar 2008 15:00 | |
| Jeff Fisher (Google) | 18 Mar 2008 17:00 |
| Subject: | Re: Detecting feed error messages in PHP![]() |
|---|---|
| From: | Cameron Hinkle (gold...@gmail.com) |
| Date: | 03/18/2008 03:00:21 PM |
| List: | com.googlegroups.google-picasa-data-api |
Well, it's not so much that I dislike Zend (I use it for Blogger), but I made my own PHP API before the Zend implementation was released and I'm trying to improve on it is all.
Thanks for the suggestion, I think I will use fopen. It would be nice if there was something in PHP that would maybe even return the response in a nice little object where I could just call out the response code and error message, but fopen() sounds like it will at least get me the info I need and I can deal with it from there. Thanks for the help!
Cameron
On Tue, Mar 18, 2008 at 2:52 PM, Jeff Fisher (Google) < api....@google.com> wrote:
Hi again,
You could use fopen() to retrieve the HTTP response, but then you have to parse the content yourself for an error response.
For reference, can you provide me some background on what it is about the Zend classes you dislike? We're looking to improve the PHP client library, so this sort of feedback would really help us prioritize what changes need to be made. :)
Cheers, -Jeff
On Mar 18, 10:47 am, "Cameron Hinkle" <gold...@gmail.com> wrote:
Yeah I noticed that file_get_contents() throws a "Warning", which is fine because it also returns FALSE on failure, so I can supress the warning and just check for false. I was hoping that there would be something that I could use instead of file_get_contents() altogether so that I would not have to do what you suggested but that's probably what I'll end up doing. I don't want to install libcurl for this, does anyone know if there are any built in PHP functions that will work as well? Would fgets() work?
Thanks, Cameron
On Tue, Mar 18, 2008 at 10:16 AM, Jeff Fisher (Google) <
api....@google.com> wrote:
Hi Cameron,
The problem here is I think file_get_contents() acts as if a bad file was given if you are using it with a web page that returns a non- successful status code. Since it appears the designers of PHP didn't include any more verbose error messages (the HTML body) in the error they generate, there is no easy way to extract this information from file_get_contents() that I can think of (PHP wizards may disagree.)
Furthermore, you problem is compounded by the fact this is not really throwing an exception, but an error, which is a separate notion in PHP that pre-dates exceptions. Granted you can still set a custom error handler:
Back to the matter at hand, the only way I think you could get at the error message would be to check if file_get_contents() failed and then use a different mechanism to try to retrieve the same resource, like cURL:
It's not perfect, but it's the simplest way I can think of off the top of my head to try to get a more useful failure message for your debugging purposes.
Of course, you could always use the GData component of the Zend Framework and get nice exceptions thrown your way... :)
Cheers, -Jeff
On Mar 18, 9:01 am, "Cameron Hinkle" <gold...@gmail.com> wrote:
This question is going to uncover my general lack of knowledge
regarding
PHP
but hopefully someone can help. I'm using the Atom feed with PHP,
not
using
Zend. To get a Picasa feed, I call file_get_contents() and pass in the query string I want. I then load the resulting string into a SimpleXMLElement. I notice that when I load a bad query string (ie;
a
query
that has an unsupported parameter) into my browser, a very helpful error message is displayed. However, file_get_contents() will not give me this message, it will just give me a warning that the file could not be found. My question is what can I do to put this error message into a
variable
so
that I can throw an exception and use it as the message?
Thanks, Cameron
"As systems developers, we have selected ourselves into the world of cool, calming, rational thought. Either our code compiles, or it doesn't. The compiler is never happy for us, nor mad at us. Perhaps this is why
we
tend
to apply logic as our main device for resolving disputes."
-Peopleware,
2nd
Edition
"Babies...before we're done here...y'all be wearing gold-plated diapers." -Rock Legend Bruce Dickinson
--http://www.cameronhinkle.com/
"As systems developers, we have selected ourselves into the world of cool, calming, rational thought. Either our code compiles, or it doesn't. The compiler is never happy for us, nor mad at us. Perhaps this is why we tend to apply logic as our main device for resolving disputes." -Peopleware, 2nd Edition
"Babies...before we're done here...y'all be wearing gold-plated diapers." -Rock Legend Bruce Dickinson
-- http://www.cameronhinkle.com/
"As systems developers, we have selected ourselves into the world of cool, calming, rational thought. Either our code compiles, or it doesn't. The compiler is never happy for us, nor mad at us. Perhaps this is why we tend to apply logic as our main device for resolving disputes." -Peopleware, 2nd Edition
"Babies...before we're done here...y'all be wearing gold-plated diapers." -Rock Legend Bruce Dickinson




