IT技术博客大学习 共学习 共进步

在sae中利用SaeFetchurl进行豆瓣的OAuth授权

Skiyo 2010-08-30 07:38:34 浏览 4,523 次

想在sae中做一个豆瓣我说功能的同步..

后来发现sae只提供了sina微博很友好的OAuth接口.

而对于其他的OAuth服务.我们不得不来用非常简陋的SaeFetchurl来实现.

再我参考了他的一些源码后.下面的代码已经完成了OAuth验证.测试正常.

注:下面的代码我只提供了使用API的时候授权的方法.你要问我怎么授权.有了这些还不够吗?

以下是代码片段:
class Douban {
    public static function saying($data) {
        global $PunnyConfig;
        $o = new OAuthClient();
        $o->setParam(’oauth_consumer_key’, $PunnyConfig[’douban’][’oauth_consumer_key’]);  //set your consumer key
        $o->setParam(’oauth_token’, $PunnyConfig[’douban’][’oauth_token’]);
        $o->setParam(’http_method’, ’POST’);                 //POST
        $o->setUrl(’http://api.douban.com/miniblog/saying’);  //broadcast api url. see http://www.douban.com/service/apidoc/reference/miniblog#添加广播
        $o->signature($PunnyConfig[’douban’][’oauth_consumer_secret’], $PunnyConfig[’douban’][’oauth_token_secret’]);  //your consumer secret and access token secret ; don’t forget signature.
        $f = new SaeFetchurl();
        $f->setMethod(’post’);
        $data = ’<?xml version=\’1.0\’ encoding=\’UTF-8\’?>’.
                ’<entry xmlns:ns0="http://www.w3.org/2005/Atom" ’.
                    ’xmlns:db="http://www.douban.com/xmlns/">’.
                    ’<content>’ . $data . ’</content>’.   //content
                ’</entry>’;
        $f->setPostData( $data );
        $f->setHeader( ’Content-Type’, ’application/atom+xml’ );
        $f->setHeader( ’Authorization’, $o->getOAuthHeaders(’YourSecret’) );
        return $f->fetch(’http://api.douban.com/miniblog/saying’);
    }
}

建议继续学习

  1. 豆瓣的Url结构方式一览 (阅读 7,822)
  2. 别得瑟了,你很可悲! (阅读 7,802)
  3. 基于PECL OAuth打造微博应用 (阅读 5,101)
  4. 深入理解OAuth与豆瓣OAuth test (阅读 4,944)
  5. 新浪微博OAuth认证流程分析 (阅读 4,921)
  6. 豆瓣是啥? (阅读 4,905)
  7. PHP for Twitter OAuth 教学演示 (阅读 4,642)
  8. SAE云服务安全沙箱绕过4(绕过文件权限防御) (阅读 4,563)
  9. SAE云服务安全沙箱绕过5(强制修改class私有权限) (阅读 4,381)
  10. OAuth那些事儿 (阅读 4,163)