Python oauth2 模块,generate_timestamp() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用oauth2.generate_timestamp()

项目:Fetch    作者:bourdakos1    | 项目源码 | 文件源码
def sign_request(self, url, url_params={}):
        oauth_request = oauth2.Request(
            method="GET",
            url=url,
            parameters=url_params
        )
        oauth_request.update(
            {
                'oauth_nonce': oauth2.generate_nonce(),
                'oauth_timestamp': oauth2.generate_timestamp(),
                'oauth_token': self.token.key,
                'oauth_consumer_key': self.consumer.key
            }
        )
        oauth_request.sign_request(
            oauth2.SignatureMethod_HMAC_SHA1(),
            self.consumer,
            self.token
        )
        return oauth_request.to_url()
项目:Fetch    作者:bourdakos1    | 项目源码 | 文件源码
def test_gen_timestamp(self):
        exp = int(time.time())
        now = oauth.generate_timestamp()
        self.assertEqual(exp, now)
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def test_gen_timestamp(self):
        exp = int(time.time())
        now = oauth.generate_timestamp()
        self.assertEqual(exp, now)
项目:api_stuff    作者:tgebhart    | 项目源码 | 文件源码
def superSecureRequest(self, host, path, url_params=None):
        """Prepares OAuth authentication and sends the request to the API.
        Args:
            host (str): The domain host of the API.
            path (str): The path of the API after the domain.
            url_params (dict): An optional set of query parameters in the request.
        Returns:
            dict: The JSON response from the request.
        Raises:
            urllib2.HTTPError: An error occurs from the HTTP request.
        """
        url_params = url_params or {}
        url = 'https://{0}{1}?'.format(host, urllib.quote(path.encode('utf8')))

        consumer = oauth2.Consumer(self.oath_consumer_key, self.oath_consumer_secret)
        oauth_request = oauth2.Request(
            method="GET", url=url, parameters=url_params)

        oauth_request.update(
            {
                'oauth_nonce': oauth2.generate_nonce(),
                'oauth_timestamp': oauth2.generate_timestamp(),
                'oauth_token': self.oath_token,
                'oauth_consumer_key': self.oath_consumer_key
            }
        )
        token = oauth2.Token(self.oath_token, self.oath_token_secret)
        oauth_request.sign_request(
            oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
        signed_url = oauth_request.to_url()

        conn = urllib2.urlopen(signed_url, None)
        try:
            response = json.loads(conn.read().decode())
        finally:
            conn.close()

        return response
项目:stewie    作者:nnewman    | 项目源码 | 文件源码
def request(host, path, url_params=None):
    """Prepares OAuth authentication and sends the request to the API.

    Args:
        host (str): The domain host of the API.
        path (str): The path of the API after the domain.
        url_params (dict): An optional set of query parameters in the request.

    Returns:
        dict: The JSON response from the request.

    Raises:
        urllib2.HTTPError: An error occurs from the HTTP request.
    """
    url_params = url_params or {}
    url = 'https://{0}{1}?'.format(host, urllib.parse.quote(path.encode('utf8')))

    consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
    oauth_request = oauth2.Request(
            method="GET", url=url, parameters=url_params)

    oauth_request.update(
            {
                'oauth_nonce': oauth2.generate_nonce(),
                'oauth_timestamp': oauth2.generate_timestamp(),
                'oauth_token': TOKEN,
                'oauth_consumer_key': CONSUMER_KEY
            }
    )
    token = oauth2.Token(TOKEN, TOKEN_SECRET)
    oauth_request.sign_request(
            oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)
    signed_url = oauth_request.to_url()

    print(('Querying {0} ...'.format(url)))

    conn = urllib.request.urlopen(signed_url, None)
    try:
        response = json.loads(conn.read().decode('utf-8'))
    finally:
        conn.close()

    return response
项目:bobafetch    作者:AnliYang    | 项目源码 | 文件源码
def request_restaurants(user_latitude, user_longitude, radius=40000, limit=20):
    """Prepares OAuth authentication and sends the request to the API."""

    user_lat_lng = user_latitude + ',' + user_longitude

    url_params = {
        'll': user_lat_lng,
        'limit': limit,
        # Sort mode: 0=Best matched (default), 1=Distance, 2=Highest Rated.
        'sort': 1,
        'category_filter': 'bubbletea',
        # Search radius in meters. Max value is 40000 meters (25 miles).
        'radius_filter': radius
    }

    url = 'https://{0}{1}?'.format(API_HOST, urllib.quote(SEARCH_PATH.encode('utf8')))

    # creates a consumer object
    consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)

    # creates a token object
    token = oauth2.Token(TOKEN, TOKEN_SECRET)

    oauth_request = oauth2.Request(
        method="GET", url=url, parameters=url_params)
    # adds more entries to the request dictionary (of parameters for the query, looks like)

    # adds oauth bits to the oauth
    oauth_request.update(
        {
            'oauth_nonce': oauth2.generate_nonce(),
            'oauth_timestamp': oauth2.generate_timestamp(),
            'oauth_token': TOKEN,
            'oauth_consumer_key': CONSUMER_KEY
        }
    )
    # hashes sensitive parts of the request
    oauth_request.sign_request(
        oauth2.SignatureMethod_HMAC_SHA1(), consumer, token)

    # generates the final url
    signed_url = oauth_request.to_url()

    # open up a connection to the signed_url
    conn = urllib2.urlopen(signed_url, None)

    try:
        response = json.loads(conn.read())
        # response = conn.read()
    finally:
        conn.close()

    yelp_location_ids = save_restaurants(response)

    return yelp_location_ids