开发者

How to get post URL out of the Blogger API in PHP

In Short, I am pulling the feed from my blogger using the Zend API in PHP. I need to get the URL that will link to that post in blogger. What is the order of functions I need to call to get that URL.

Right now I am pulling the data using:

$query = new Zend_Gdata_Query('http://www.blogger.com/feeds/MYID/posts/default');
$query->setParam('max-results', "1");
$feed = $gdClient->getFeed($query);
$newestPost = $feed->entry[0];

I can not for the life of me figure out where I have to go from here to get the URL. I can successfully get the Post title using: $newestPost->getTitle() and I can get the body by using $newestPost->getContent()->getText(). I have tried a lot of function calls, even ones in the documentation and most of them error out. I have printed out the entire object to look through it and I can find the data I want (so I know it is there) but the object is too complex to be able to just look at and see what I have to do to get to that data.

If anyone can help me or at 开发者_JS百科least point me to a good explanation of how that Object is organized and how to get to each sub object within it, that would be greatly appreciated.

EDIT: Never mind I figured it out.


You are almost there, really all you need to do is once you have your feed entry is access the link element inside. I like pretty URLs so I went with the alternate rather than the self entry in the atom feed.

$link = $entry->link[4]->href;

where $entry is the entry that you are setting from the feed.


The solution is:

$query = new Zend_Gdata_Query('http://www.blogger.com/feeds/MyID/posts/default');

$query->setParam('max-results', "1");

$feed = $gdClient->getFeed($query);

$newestPost = $feed->entry[0];

$body = $newestPost->getContent()->getText();

$body now contains the post contents of the latest post (or entry[0]) from the feed. This is just the contents of the body of the post, not the title or any other data or formatting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜