示例#1
0
  /**
   * pretty much a helper function to set up the request
   */
  public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
    $parameters = ($parameters) ?  $parameters : array();
    $defaults = array("oauth_version" => Blogger_OAuthRequest::$version,
                      "oauth_nonce" => Blogger_OAuthRequest::generate_nonce(),
                      "oauth_timestamp" => Blogger_OAuthRequest::generate_timestamp(),
                      "oauth_consumer_key" => $consumer->key);
    if ($token)
      $defaults['oauth_token'] = $token->key;

    $parameters = array_merge($defaults, $parameters);

    return new Blogger_OAuthRequest($http_method, $http_url, $parameters);
  }
        /**
         *  Get a URL using the oauth token for authentication (returns false on failure)
         */
        function oauth_get($url,$params = null)
        {
            $test_consumer = new Blogger_OAuthConsumer('anonymous', 'anonymous', null);
            $goog = new Blogger_OAuthConsumer($this->token, $this->secret, null);
            $request = new Blogger_OAuthRequest("GET", $url, $params);

            //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
            $blog_req = $request->from_consumer_and_token($test_consumer, $goog, 'GET', $url, $params);

            $blog_req->sign_request(new Blogger_OAuthSignatureMethod_HMAC_SHA1(), $test_consumer, $goog);

            $data = wp_remote_get($blog_req->to_url(), array('sslverify' => false, 'timeout' => Blogger_Import::REMOTE_TIMEOUT));

            if (wp_remote_retrieve_response_code($data) == 200)
            {
                $response = wp_remote_retrieve_body($data);
            } else
            {
                $response = false;
            }

            return $response;
        }