使用 PHP Pecl OAuth 发布博文,不使用 Zend GData
我的 FreeBSD Web 服务器不支持 Zend Framework,因此我尝试使用 php 的 pecl oauth 扩展来解决这个问题。经过几个小时的谷歌搜索和一天的实施后,我收到了一份博客列表,但我无法发布新的博客文章。 我发现这个使用 OAuth PHP Pecl 扩展发布到博主 Feed 和像那里一样实施。 这是我的解决方案的一部分:
$data = '<entry xmlns=\'http://www.w3.org/2005/Atom\'>
<title type=\'text\'>Marriage!</title>
<content type=\'xhtml\'>
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>
<p>He is the last man on earth I would ever desire to marry</p>
<p>Whatever shall I do?</p>
</div>
</content>
<category scheme="http://www.blogger.com/atom/ns#" term="marriage" />
<category scheme="http://www.blogger.com/atom/ns#" term="Mr. Darcy" />
</entry>';
$params = array(
'request_token_url' => 'https://www.google.com/accounts/OAuthGetRequestToken',
'request_token_url_data' => array('scope' => 'http://www.blogger.com/feeds', 'oauth_callback' => $callback_url),
'autorize_url' => 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_token_url' => 'https://www.google.com/accounts/OAuthGetAccessToken',
'callback_url' => $callback_url,
'call_url' => 'http://www.blogger.com/feeds/{$blog->id}/posts/default',
'call_url_data' => $data,
'service' => 'google',
'method' => OAUTH_HTTP_METHOD_POST,
'header' => array('Content-Type' => 'application/atom+xml'),
假设我已经拥有 OAuth 令牌。
$oauth->setToken($_SESSION[$oauth_token],$_SESSION[$oauth_secret]);
$oauth->fetch($params['call_url'], $params['call_url_data'], $params['method'], $params['header'])
return $oauth->getLastResponse();
我收到的回应:
400 BAD REQUEST 请求 URI 或标头无效,或不受支持 非标准参数
,我卡在这里。也许 $data 格式不正确?
My FreeBSD web-server does not support Zend Framework, so I'm trying figure it out with php's pecl oauth extension. After hours of googling and a day of implementing i recieved a list of blogs, but i cant post a new blog post.
i found this Using the OAuth PHP Pecl extension to post to blogger feed and implemented like there.
Here is a part of my solution:
$data = '<entry xmlns=\'http://www.w3.org/2005/Atom\'>
<title type=\'text\'>Marriage!</title>
<content type=\'xhtml\'>
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>
<p>He is the last man on earth I would ever desire to marry</p>
<p>Whatever shall I do?</p>
</div>
</content>
<category scheme="http://www.blogger.com/atom/ns#" term="marriage" />
<category scheme="http://www.blogger.com/atom/ns#" term="Mr. Darcy" />
</entry>';
$params = array(
'request_token_url' => 'https://www.google.com/accounts/OAuthGetRequestToken',
'request_token_url_data' => array('scope' => 'http://www.blogger.com/feeds', 'oauth_callback' => $callback_url),
'autorize_url' => 'https://www.google.com/accounts/OAuthAuthorizeToken',
'access_token_url' => 'https://www.google.com/accounts/OAuthGetAccessToken',
'callback_url' => $callback_url,
'call_url' => 'http://www.blogger.com/feeds/{$blog->id}/posts/default',
'call_url_data' => $data,
'service' => 'google',
'method' => OAUTH_HTTP_METHOD_POST,
'header' => array('Content-Type' => 'application/atom+xml'),
assuming that I already have OAuth token.
$oauth->setToken($_SESSION[$oauth_token],$_SESSION[$oauth_secret]);
$oauth->fetch($params['call_url'], $params['call_url_data'], $params['method'], $params['header'])
return $oauth->getLastResponse();
in response i recieve:
400 BAD REQUEST Invalid request URI or header, or unsupported
nonstandard parameter
and i stuck here. maybe $data is not well formatted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论