I was successfully able to access the blogger api using the pecl oauth 
library. I wrote a simple wrapper class for the oauth library which included 
the following functions:

        function getBloggerAccessToken($oauth_token, $extraParams=array()){
        try{
            $oauth = new 
OAuth($this->consumer_key,$this->consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
            $oauth->setToken($oauth_token, 
WebApplication::getSession('oauth_secret'));
            $access_token_info = 
$oauth->getAccessToken($this->access_token_url);
            $_SESSION['token'] = $access_token_info['oauth_token'];
            $_SESSION['secret'] = $access_token_info['oauth_token_secret'];
            return $access_token_info;
        }catch( OAuthException $E) {
               print_r($E);
               exit;
        }
    }

    function getBloggerRequestToken($extraParams=array()){
       
        try {
          $oauth = new 
OAuth($this->consumer_key,$this->consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
 

            $res = $oauth->fetch($this->request_token_url, $extraParams);
            $request_token_info = $oauth->getLastResponse();
            $results = array();
            parse_str($request_token_info, $results);
            $info = $oauth->getLastResponseInfo();
            $_SESSION['oauth_secret'] =  $results['oauth_token_secret'];
            header('Location: 
'.$this->authorize_url.'?oauth_token='.$results['oauth_token']);
            exit;

        } catch(OAuthException $E) {
               print_r($E);
               echo "<hr/>";
               print_r($info);
               exit;
        }
    }



Then it's as simple as the following call:

if(!$_GET['oauth_token']){
    
$blogObj->getBloggerRequestToken(array("scope"=>"http://www.blogger.com/feeds/";,
 
"oauth_callback"=>YOUR_CALLBACK)));
}else{
    $access_array = $blogObj->getBloggerAccessToken($_GET['oauth_token']);
}

One thing to point out: 
the 'scope' is really important for getting a request token, it wont work 
without this! i couldnt get the oauth library 'getRequestToken' function to 
work because it wouldn't allow me to pass in the extra 'scope' parameter, 
hence the reason that I'm using the 'fetch' function. 

Hope this is helpful!

-- 
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/oauth?hl=en.

Reply via email to