技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> PHP --> 在sae中利用SaeFetchurl进行豆瓣的OAuth授权

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

浏览:3355次  出处信息

想在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结构方式一览    (阅读:6446)
  2. 别得瑟了,你很可悲!    (阅读:6182)
  3. 新浪微博OAuth认证流程分析    (阅读:3950)
  4. 基于PECL OAuth打造微博应用    (阅读:3840)
  5. 深入理解OAuth与豆瓣OAuth test    (阅读:3688)
  6. PHP for Twitter OAuth 教学演示    (阅读:3414)
  7. SAE云服务安全沙箱绕过4(绕过文件权限防御)    (阅读:3377)
  8. SAE云服务安全沙箱绕过5(强制修改class私有权限)    (阅读:3214)
  9. OAuth那些事儿    (阅读:3152)
  10. SAE云服务安全沙箱绕过3(绕过命令执行防御)    (阅读:2930)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1