当前位置: 首页>>代码示例>>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;未经允许,请勿转载。