使用 Zend Gdata 发布到博客
我正在尝试使用以下代码发布到我的博客帐户,但它似乎不起作用。我是这方面的新手,我错过了什么吗?谢谢... `
<?php
$user = '[email protected]';
$pass = 'password';
// I have to admit, I would normally use the autoloader
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Feed');
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'blogger', null,
Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$gdClient = new Zend_Gdata($client);
function createPublishedPost()
{
$title='Hello, world!';
$content='I am blogging on the internet.';
$blogID= "4419618066922958909";
$uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
$entry = $gdClient->newEntry();
$entry->title = $gdClient->newTitle($title);
$entry->content = $gdClient->newContent($content);
$entry->content->setType('text');
$createdPost = $gdClient->insertEntry($entry, $uri);
$idText = split('-', $createdPost->id->text);
$newPostID = $idText[2];
return $newPostID;
}
$ret = createPublishedPost();
echo $ret;
?>
`
I am trying to post to my blogger account using the below code but it does not seem to work. I am a newbie with this, am I missing anything? Thanks...
`
<?php
$user = '[email protected]';
$pass = 'password';
// I have to admit, I would normally use the autoloader
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Feed');
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'blogger', null,
Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$gdClient = new Zend_Gdata($client);
function createPublishedPost()
{
$title='Hello, world!';
$content='I am blogging on the internet.';
$blogID= "4419618066922958909";
$uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
$entry = $gdClient->newEntry();
$entry->title = $gdClient->newTitle($title);
$entry->content = $gdClient->newContent($content);
$entry->content->setType('text');
$createdPost = $gdClient->insertEntry($entry, $uri);
$idText = split('-', $createdPost->id->text);
$newPostID = $idText[2];
return $newPostID;
}
$ret = createPublishedPost();
echo $ret;
?>
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了您使用的代码之外,我们很难知道出了什么问题。因此,首先您需要:
请参阅代码中的注释以查看我更改的内容:
It's hard for us to know what goes wrong without knowing anything more than what code you are using. So first of you need to:
See comments in code to see what I have changed:
通过一些实验得到了它......在函数内移动了
$gdClient = new Zend_Gdata($client);
。以前它没有在全球范围内声明。Got it with some experimentation...Moved
$gdClient = new Zend_Gdata($client);
inside the function. Previously it is not globally declared.