當前位置: 首頁>>代碼示例>>Python>>正文


Python requests_oauthlib.OAuth1Session方法代碼示例

本文整理匯總了Python中requests_oauthlib.OAuth1Session方法的典型用法代碼示例。如果您正苦於以下問題:Python requests_oauthlib.OAuth1Session方法的具體用法?Python requests_oauthlib.OAuth1Session怎麽用?Python requests_oauthlib.OAuth1Session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests_oauthlib的用法示例。


在下文中一共展示了requests_oauthlib.OAuth1Session方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def __init__(self, owner_or_token):
        if isinstance(owner_or_token, User):
            self.token = QuickbooksToken.objects.filter(user=owner_or_token).first()
        elif isinstance(owner_or_token, QuickbooksToken):
            self.token = owner_or_token
        else:
            raise ValueError("API must be initialized with either a QuickbooksToken or User")

        session = OAuth1Session(client_key=settings.QUICKBOOKS['CONSUMER_KEY'],
                                client_secret=settings.QUICKBOOKS['CONSUMER_SECRET'],
                                resource_owner_key=self.token.access_token,
                                resource_owner_secret=self.token.access_token_secret)

        session.headers.update({'content-type': 'application/json', 'accept': 'application/json'})
        self.session = session
        self.realm_id = self.token.realm_id
        self.data_source = self.token.data_source
        self.url_base = {'QBD': QUICKBOOKS_DESKTOP_V3_URL_BASE,
                         'QBO': QUICKBOOKS_ONLINE_V3_URL_BASE}[self.token.data_source] 
開發者ID:grue,項目名稱:django-quickbooks-online,代碼行數:21,代碼來源:api.py

示例2: start_oauth

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def start_oauth():
    next_page = request.args.get('next')
    if next_page:
        session['next'] = next_page

    client_key = app.config['CLIENT_KEY']
    client_secret = app.config['CLIENT_SECRET']

    request_token_url = 'https://www.openstreetmap.org/oauth/request_token'

    callback = url_for('oauth_callback', _external=True)

    oauth = OAuth1Session(client_key,
                          client_secret=client_secret,
                          callback_uri=callback)
    fetch_response = oauth.fetch_request_token(request_token_url)

    session['owner_key'] = fetch_response.get('oauth_token')
    session['owner_secret'] = fetch_response.get('oauth_token_secret')

    base_authorization_url = 'https://www.openstreetmap.org/oauth/authorize'
    authorization_url = oauth.authorization_url(base_authorization_url,
                                                oauth_consumer_key=client_key)
    return redirect(authorization_url) 
開發者ID:EdwardBetts,項目名稱:osm-wikidata,代碼行數:26,代碼來源:view.py

示例3: tweet

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def tweet(self, s, media=None):
        if media is None:
            params = {"status": s}
        else:
            params = {"status": s, "media_ids": [media]}

        from requests_oauthlib import OAuth1Session

        CK = self._preset_ck if self.consumer_key_type == 'ikalog' else self.consumer_key
        CS = self._preset_cs if self.consumer_key_type == 'ikalog' else self.consumer_secret

        twitter = OAuth1Session(
            CK, CS, self.access_token, self.access_token_secret)
        return twitter.post(self.url, params=params, verify=self._get_cert_path())

    ##
    # Post a screenshot to Twitter
    # @param  self    The object pointer.
    # @param  img     The image to be posted.
    # @return media   The media ID
    # 
開發者ID:hasegaw,項目名稱:IkaLog,代碼行數:23,代碼來源:twitter.py

示例4: check_import

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def check_import(self):
        try:
            from requests_oauthlib import OAuth1Session
        except:
            print("モジュール requests_oauthlib がロードできませんでした。 Twitter 投稿ができません。")
            print("インストールするには以下のコマンドを利用してください。\n    pip install requests_oauthlib\n")

    ##
    # Constructor
    # @param self              The Object Pointer.
    # @param consumer_key      Consumer key of the application.
    # @param consumer_secret   Comsumer secret.
    # @param auth_token        Authentication token of the user account.
    # @param auth_token_secret Authentication token secret.
    # @param attach_image      If true, post screenshots.
    # @param footer            Footer text.
    # @param tweet_my_score    If true, post score.
    # @param tweet_kd          If true, post killed/death.
    # @param tweet_udemae      If true, post udemae(rank).
    # @param use_reply         If true, post the tweet as a reply to @_ikalog_
    # 
開發者ID:hasegaw,項目名稱:IkaLog,代碼行數:23,代碼來源:twitter.py

示例5: get_authorization_url

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def get_authorization_url(self, callback_uri):
        session = OAuth1Session(
            settings.OAUTH_CONSUMER_KEY,
            client_secret=settings.OAUTH_CONSUMER_SECRET,
            callback_uri=callback_uri,
        )
        try:
            url = settings.API_HOST + settings.OAUTH_TOKEN_PATH
            response = session.fetch_request_token(url, verify=settings.VERIFY)
        except (ValueError, TokenRequestDenied, ConnectionError) as err:
            raise AuthenticatorError(err)
        else:
            self.token = response.get('oauth_token')
            self.secret = response.get('oauth_token_secret')
        url = settings.API_HOST + settings.OAUTH_AUTHORIZATION_PATH
        authorization_url = session.authorization_url(url)
        LOGGER.log(logging.INFO, 'Initial token {}, secret {}'.format(
            self.token, self.secret))
        return authorization_url 
開發者ID:OpenBankProject,項目名稱:API-Manager,代碼行數:21,代碼來源:oauth.py

示例6: set_access_token

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def set_access_token(self, authorization_url):
        session = OAuth1Session(
            settings.OAUTH_CONSUMER_KEY,
            settings.OAUTH_CONSUMER_SECRET,
            resource_owner_key=self.token,
            resource_owner_secret=self.secret,
        )
        session.parse_authorization_response(authorization_url)
        url = settings.API_HOST + settings.OAUTH_ACCESS_TOKEN_PATH
        try:
            response = session.fetch_access_token(url)
        except (TokenRequestDenied, ConnectionError) as err:
            raise AuthenticatorError(err)
        else:
            self.token = response.get('oauth_token')
            self.secret = response.get('oauth_token_secret')
        LOGGER.log(logging.INFO, 'Updated token {}, secret {}'.format(
            self.token, self.secret)) 
開發者ID:OpenBankProject,項目名稱:API-Manager,代碼行數:20,代碼來源:oauth.py

示例7: __init__

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def __init__(
        self, client_key, client_secret, resource_owner_key, resource_owner_secret
    ):
        """__init_()
           """
        self.client_key = client_key
        self.client_secret = client_secret
        self.resource_owner_key = resource_owner_key
        self.resource_owner_secret = resource_owner_secret
        self.base_url_prod = r"https://api.etrade.com/v1/accounts"
        self.base_url_dev = r"https://apisb.etrade.com/v1/accounts"
        self.session = OAuth1Session(
            self.client_key,
            self.client_secret,
            self.resource_owner_key,
            self.resource_owner_secret,
            signature_type="AUTH_HEADER",
        ) 
開發者ID:jessecooper,項目名稱:pyetrade,代碼行數:20,代碼來源:accounts.py

示例8: get_auth_token

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def get_auth_token(self):
        """
        Retrieves an auth_session_token using DEP server token data prepared as an
        OAuth1Session() instance earlier on.
        """
        # Retrieve session auth token
        get_session = self.dep_prep('session', 'get', authsession=self.oauth)
        response = self.oauth.send(get_session)

        # Extract the auth session token from the JSON reply
        token = response.json()['auth_session_token']

        # The token happens to contain the UNIX timestamp of when it was generated
        # so we save it for later reference.
        timestamp = token[:10]

        # Roll a human-readable timestamp as well.
        ts_readable = datetime.datetime.fromtimestamp(
                      int(timestamp)).strftime(
                      '%Y-%m-%d %H:%M:%S')

        print "Token generated at %s" % ts_readable

        return token, timestamp 
開發者ID:bruienne,項目名稱:depy,代碼行數:26,代碼來源:depy.py

示例9: get_trends

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def get_trends(self, local):
        """
        Method to get the trending hashtags.

        :type local: str
        :rtype: list of str
        """
        session_string = "https://api.twitter.com/1.1/trends/place.json?id="
        local_id = self.get_local_identifier()[local]
        session_string += local_id
        session = OAuth1Session(ConsumerKey,
                                ConsumerSecret,
                                AccessToken,
                                AccessTokenSecret)
        response = session.get(session_string)
        if response.__dict__['status_code'] == 200:
            local_trends = json.loads(response.text)[0]["trends"]
            hashtags = [trend["name"]
                        for trend in local_trends if trend["name"][0] == '#']
        else:
            hashtags = []
        return hashtags 
開發者ID:felipessalvatore,項目名稱:MyTwitterBot,代碼行數:24,代碼來源:Bot.py

示例10: update_twitter_profile_data

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def update_twitter_profile_data(self):
        if not self.twitter or not self.twitter_creds:
            print u"Can't update twitter, doesn't have twitter username or twitter_creds"
            return None

        oauth = OAuth1Session(
            os.getenv('TWITTER_CONSUMER_KEY'),
            client_secret=os.getenv('TWITTER_CONSUMER_SECRET')
        )
        url = "https://api.twitter.com/1.1/users/lookup.json?screen_name={}".format(self.twitter)
        r = oauth.get(url)
        response_data = r.json()
        first_profile = response_data[0]

        keys_to_update = ["profile_image_url", "profile_image_url_https"]
        for k in keys_to_update:
            self.twitter_creds[k] = first_profile[k]

        print u"Updated twitter creds for @{}".format(self.twitter)

        return self.twitter_creds 
開發者ID:ourresearch,項目名稱:impactstory-tng,代碼行數:23,代碼來源:person.py

示例11: __setup_service

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def __setup_service(self, url, provided_oauth):
        oauth = None
        if provided_oauth is not None:
            return provided_oauth
        else:
            if self.config is not None:
                oauth = OAuth1Session(
                    self.config["app_token"],
                    client_secret=self.config["app_secret"],
                    resource_owner_key=self.config["access_token"],
                    resource_owner_secret=self.config["access_token_secret"],
                    realm=url,
                )

                if oauth is None:
                    raise ConnectionError("Failed to establish OAuth session.")
                else:
                    return oauth 
開發者ID:andli,項目名稱:pymkm,代碼行數:20,代碼來源:pymkmapi.py

示例12: test_get_articles

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def test_get_articles(self):
        mock_oauth = Mock(spec=OAuth1Session)
        mock_oauth.get = MagicMock(
            return_value=self.MockResponse(
                TestCommon.cardmarket_find_user_articles_result, 200, "testing ok"
            )
        )
        product_id = 1

        result = self.api.get_articles(product_id, 0, mock_oauth)
        self.assertEqual(result[0]["comments"], "x")

        mock_oauth.get = MagicMock(
            return_value=self.MockResponse(
                TestCommon.cardmarket_find_user_articles_result, 206, "partial content"
            )
        )
        product_id = 1

        result = self.api.get_articles(product_id, 0, mock_oauth)
        self.assertEqual(result[0]["comments"], "x") 
開發者ID:andli,項目名稱:pymkm,代碼行數:23,代碼來源:test_pymkmapi.py

示例13: test_find_user_articles

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def test_find_user_articles(self):

        mock_oauth = Mock(spec=OAuth1Session)
        mock_oauth.get = MagicMock(
            return_value=self.MockResponse(
                TestCommon.cardmarket_find_user_articles_result, 200, "testing ok"
            )
        )
        user_id = 1
        game_id = 1

        result = self.api.find_user_articles(user_id, game_id, 0, mock_oauth)
        self.assertEqual(result[0]["comments"], "x")

        mock_oauth.get = MagicMock(
            return_value=self.MockResponse(
                TestCommon.cardmarket_find_user_articles_result, 206, "partial content"
            )
        )

        result = self.api.find_user_articles(user_id, game_id, 0, mock_oauth)
        self.assertEqual(result[0]["comments"], "x") 
開發者ID:andli,項目名稱:pymkm,代碼行數:24,代碼來源:test_pymkmapi.py

示例14: __init__

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def __init__(self, consumer_key, consumer_secret, callback=None):
        if type(consumer_key) == six.text_type:
            consumer_key = consumer_key.encode('ascii')

        if type(consumer_secret) == six.text_type:
            consumer_secret = consumer_secret.encode('ascii')

        self.consumer_key = consumer_key
        self.consumer_secret = consumer_secret
        self.access_token = None
        self.access_token_secret = None
        self.callback = callback
        self.username = None
        self.oauth = OAuth1Session(consumer_key,
                                   client_secret=consumer_secret,
                                   callback_uri=self.callback) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:18,代碼來源:auth.py

示例15: get_access_token

# 需要導入模塊: import requests_oauthlib [as 別名]
# 或者: from requests_oauthlib import OAuth1Session [as 別名]
def get_access_token(self, verifier=None):
        """
        After user has authorized the request token, get access token
        with user supplied verifier.
        """
        try:
            url = self._get_oauth_url('access_token')
            self.oauth = OAuth1Session(self.consumer_key,
                                       client_secret=self.consumer_secret,
                                       resource_owner_key=self.request_token['oauth_token'],
                                       resource_owner_secret=self.request_token['oauth_token_secret'],
                                       verifier=verifier, callback_uri=self.callback)
            resp = self.oauth.fetch_access_token(url)
            self.access_token = resp['oauth_token']
            self.access_token_secret = resp['oauth_token_secret']
            return self.access_token, self.access_token_secret
        except Exception as e:
            raise TweepError(e) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:20,代碼來源:auth.py


注:本文中的requests_oauthlib.OAuth1Session方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。