views:

403

answers:

3

Hi all, I need to connect my php script to Gmail Atom feed to retrieve the count of unread messages, but I have problem on get the xml feed file:

if($xmlGmailFeed = simplexml_load_file("https://USERNAME:[email protected]/gmail/feed/atom/")) 
    $unreadMessages = $xmlGmailFeed->fullcount;

gives: failed to load external entity ho can I do? thaks :)

error! failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized

A: 

Try using:

https://USERNAME:[email protected]/mail/feed/atom/
jmans
it is the same..
frx08
A: 

first try and do a file_get_contents to see if the feed is ok and you have allow_url_fopen enabled. Then you could try and save it a temporary file and pass that path to simplexml_load_file.

If the above work, and you have php < 5.1.0 you could try and do

simplexml_load_file(rawurlencode("https://USERNAME:[email protected]/gmail/feed/atom/"))

Since PHP 5.1.0 you don't need to do this because PHP will do it for you.

solomongaby
I use php 5.3.0, I think it's an authorization problem
frx08
+1  A: 

Yeah, sounds like a authentication error. I believe you have to authenticate using curl, as simplexml_load_file don't suffice. Take a look at the GmAtom class. It will do the trick, or at least point you in the right direction.

tdolsen