当前位置: 首页>>代码示例>>Python>>正文


Python Client.request方法代码示例

本文整理汇总了Python中sanction.client.Client.request方法的典型用法代码示例。如果您正苦于以下问题:Python Client.request方法的具体用法?Python Client.request怎么用?Python Client.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sanction.client.Client的用法示例。


在下文中一共展示了Client.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle_facebook_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_facebook_login(self, data):
        c = Client(
            token_endpoint='https://graph.facebook.com/oauth/access_token',
            resource_endpoint='https://graph.facebook.com',
            redirect_uri='http://localhost/login/facebook',
            client_id=config['facebook.client_id'],
            client_secret=config['facebook.client_secret'])

        c.request_token(code=data['code'],
            parser=lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        d = c.request('/me')
        self.dump_response(d)

        try:
            d = c.request('/me/feed', data=urlencode({
                'message': 'test post from py-sanction'
            }))
            self.wfile.write(
                'I posted a message to your wall (in sandbox mode, nobody '
                'else will see it)'.encode(ENCODING_UTF8))
        except:
            self.wfile.write(
                'Unable to post to your wall')
开发者ID:kobeBigs,项目名称:sanction,代码行数:27,代码来源:server.py

示例2: handle_facebook_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
	def handle_facebook_login(self, data):
		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.log_message(self.path)
		self.end_headers()

		c = Client(
			token_endpoint="https://graph.facebook.com/oauth/access_token",
			resource_endpoint="https://graph.facebook.com",
			redirect_uri="http://localhost:8080/login/facebook",
			client_id=config["facebook.client_id"],
			client_secret=config["facebook.client_secret"])
		c.request_token(data=data, 
			parser = lambda data: dict(parse_qsl(data)))

		d = c.request("/me")

		self.wfile.write("Access token: %s<br>" % c.access_token)
		self.wfile.write("First name: %s<br>" % d["first_name"])
		self.wfile.write("Last name: %s<br>" % d["last_name"])
		self.wfile.write("Email: %s<br>" % d["email"])

		# to see a wall post in action, uncomment this
		try:
			d = c.request("/me/feed", data=urlencode({
				"message": "test post from py-sanction"
			}))
			self.wfile.write(
				"I posted a message to your wall (in sandbox mode, nobody else will see it)")
		except:
			self.wfile.write(
				"Unable to post to your wall")
开发者ID:AlecTaylor,项目名称:sanction,代码行数:34,代码来源:server.py

示例3: test_inst

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def test_inst(self):
        from urlparse import urlparse
        from urlparse import parse_qsl
        from sanction.client import Client

        c = get_config()
        client = Client(TestAdapterImpl, c)
        uri = client.flow.authorization_uri()
        o = urlparse(uri)
        qs = dict(parse_qsl(o.query))

        self.assertEquals(qs["scope"], c["testadapterimpl.scope"])
        self.assertEquals(qs["redirect_uri"],
            c["testadapterimpl.redirect_uri"])
        self.assertEquals(qs["response_type"], "code")
        self.assertEquals(qs["client_id"], c["testadapterimpl.client_id"])
        
        start_server()
        cred = client.flow.authorization_received({
            "code": "test"
        })
        self.assertTrue(isinstance(cred, BearerCredentials))

        start_server()
        r = client.request("/me")
开发者ID:nirleka,项目名称:py-sanction,代码行数:27,代码来源:test_client.py

示例4: handle_foursquare_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
	def handle_foursquare_login(self, data):
		self.send_response(200)
		self.send_header("Content-type", "text/html")
		self.log_message(self.path)
		self.end_headers()

		c = Client(
			token_endpoint="https://foursquare.com/oauth2/access_token",
			resource_endpoint="https://api.foursquare.com/v2",
			redirect_uri="http://localhost:8080/login/foursquare",
			client_id=config["foursquare.client_id"],
			client_secret=config["foursquare.client_secret"],
			)
		c.access_token_key = "oauth_token"
		c.request_token(data=data)

		d = c.request("/users/24700343")

		self.wfile.write("Access token: %s<br>" % c.access_token)
		self.wfile.write("First name: %s<br>" % 
			d["response"]["user"]["firstName"])
		self.wfile.write("Last name: %s<br>" % 
			d["response"]["user"]["lastName"])
		self.wfile.write("Email: %s<br>" % 
			d["response"]["user"]["contact"]["email"])
开发者ID:AlecTaylor,项目名称:sanction,代码行数:27,代码来源:server.py

示例5: handle_foursquare_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_foursquare_login(self, data):
        def token_transport(url, access_token, data=None, method=None):
            parts = urlsplit(url)
            query = dict(parse_qsl(parts.query))
            query.update({
                'oauth_token': access_token
            })
            url = urlunsplit((parts.scheme, parts.netloc, parts.path,
                urlencode(query), parts.fragment))
            try:
                req = Request(url, data=data, method=method)
            except TypeError:
                req = Request(url, data=data)
                req.get_method = lambda: method
            return req

        c = Client(
            token_endpoint='https://foursquare.com/oauth2/access_token',
            resource_endpoint='https://api.foursquare.com/v2',
            redirect_uri='http://localhost/login/foursquare',
            client_id=config['foursquare.client_id'],
            client_secret=config['foursquare.client_secret'],
            token_transport=token_transport
            )
        c.request_token(code=data['code'])

        self.dump_client(c)
        d = c.request('/users/24700343')
        self.dump_response(d)
开发者ID:brianru,项目名称:sanction,代码行数:31,代码来源:server.py

示例6: handle_stackexchange_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_stackexchange_login(self, data):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.log_message(self.path)
        self.end_headers()

        c = Client(StackExchange, get_config())
        cred = c.flow.authorization_received(data)

        d = c.request("/me", body=urlencode({
            "site": "stackoverflow"
        }))

        self.wfile.write("<!DOCTYPE html>")
        self.wfile.write("<head><meta charset=\"utf-8\"/></head><body>")
        self.wfile.write("Access token: %s<br>" % cred.access_token)
        self.wfile.write("Type: %s<br>" % cred.token_type)
        self.wfile.write("Expires in: %d<br>" % cred.expires_in)

        # stackexchange gzips all data
        h = StringIO(d)
        gzip_data = GzipFile(fileobj=h)
        d = gzip_data.read()
        gzip_data.close()
        self.wfile.write(d)
        self.wfile.write("</body></html>")
开发者ID:nirleka,项目名称:py-sanction,代码行数:28,代码来源:server.py

示例7: handle_instagram_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_instagram_login(self, data):
        c = Client(token_endpoint="https://api.instagram.com/oauth/access_token",
            resource_endpoint="https://api.instagram.com/v1",
            redirect_uri="http://localhost/login/instagram",
            client_id=config["instagram.client_id"],
            client_secret=config["instagram.client_secret"])
        c.request_token(code=data["code"])

        self.dump_client(c)
        data = c.request("/users/self")["data"]
        self.dump_response(data)
开发者ID:Raekkeri,项目名称:sanction,代码行数:13,代码来源:server.py

示例8: handle_github_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_github_login(self, data):
        c = Client(token_endpoint="https://github.com/login/oauth/access_token",
            resource_endpoint="https://api.github.com",
            redirect_uri="http://localhost/login/github",
            client_id=config["github.client_id"],
            client_secret=config["github.client_secret"])
        c.request_token(code=data["code"],
            parser=lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        data = c.request("/user")
        self.dump_response(data)
开发者ID:Raekkeri,项目名称:sanction,代码行数:14,代码来源:server.py

示例9: handle_bitly_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_bitly_login(self, data):
        c = Client(token_endpoint="https://api-ssl.bitly.com/oauth/access_token",
            resource_endpoint="https://api-ssl.bitly.com",
            redirect_uri="http://localhost/login/bitly",
            client_id=config["bitly.client_id"],
            client_secret=config["bitly.client_secret"])
        c.request_token(code=data["code"],
            parser=lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        data = c.request("/v3/user/info")["data"]
        self.dump_response(data)
开发者ID:Raekkeri,项目名称:sanction,代码行数:14,代码来源:server.py

示例10: handle_deviantart_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_deviantart_login(self, data):
        c = Client(
            token_endpoint='https://www.deviantart.com/oauth2/draft15/token',
            resource_endpoint='https://www.deviantart.com/api/draft15',
            redirect_uri=config['deviantart.redirect_uri'],
            client_id=config['deviantart.client_id'],
            client_secret=config['deviantart.client_secret'])
        c.request_token(code=data['code'])

        self.dump_client(c)
        data = c.request('/user/whoami')
        self.dump_response(data)
开发者ID:kobeBigs,项目名称:sanction,代码行数:14,代码来源:server.py

示例11: handle_foursquare_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_foursquare_login(self, data):
        c = Client(
            token_endpoint="https://foursquare.com/oauth2/access_token",
            resource_endpoint="https://api.foursquare.com/v2",
            redirect_uri="http://localhost/login/foursquare",
            client_id=config["foursquare.client_id"],
            client_secret=config["foursquare.client_secret"],
            )
        c.access_token_key = "oauth_token"
        c.request_token(code=data["code"])

        self.dump_client(c)
        d = c.request("/users/24700343")
        self.dump_response(d)
开发者ID:Raekkeri,项目名称:sanction,代码行数:16,代码来源:server.py

示例12: test_facebook_client_credentials

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def test_facebook_client_credentials(self):
        c = Client(
            token_endpoint="https://graph.facebook.com/oauth/access_token",
            resource_endpoint="https://graph.facebook.com",
            client_id="285809954824916",
            client_secret="d985f6a3ecaffd11d61b3cd026b8753a")

        self.assertEquals(c.access_token, None)
        c.request_token(parser=lambda data: dict(parse_qsl(data)),
            grant_type="client_credentials")
        self.assertIsNotNone(c.access_token)

        data = c.request("/app")
        self.assertEquals(data["name"], "sanction")
开发者ID:brianru,项目名称:sanction,代码行数:16,代码来源:tests.py

示例13: handle_facebook_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_facebook_login(self, data):
        c = Client(
            token_endpoint="https://graph.facebook.com/oauth/access_token",
            resource_endpoint="https://graph.facebook.com",
            redirect_uri="http://localhost/login/facebook",
            client_id=config["facebook.client_id"],
            client_secret=config["facebook.client_secret"])

        c.request_token(code=data["code"],
            parser=lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        d = c.request("/me")
        self.dump_response(d)

        try:
            d = c.request("/me/feed", data=urlencode({
                "message": "test post from py-sanction"
            }))
            self.wfile.write(
                "I posted a message to your wall (in sandbox mode, nobody else will see it)")
        except:
            self.wfile.write(
                "Unable to post to your wall")
开发者ID:Raekkeri,项目名称:sanction,代码行数:26,代码来源:server.py

示例14: handle_deviantart_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_deviantart_login(self, data):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.log_message(self.path)
        self.end_headers()

        c = Client(DeviantArt, get_config())
        cred = c.flow.authorization_received(data)

        d = c.request("/placebo")

        self.wfile.write("Access token: %s<br>" % cred.access_token)
        self.wfile.write("Type: %s<br>" % cred.token_type)
        self.wfile.write("Expires in: %d<br>" % cred.expires_in)

        self.wfile.write(d)
开发者ID:nirleka,项目名称:py-sanction,代码行数:18,代码来源:server.py

示例15: handle_stackexchange_login

# 需要导入模块: from sanction.client import Client [as 别名]
# 或者: from sanction.client.Client import request [as 别名]
    def handle_stackexchange_login(self, data):
        c = Client(token_endpoint="https://stackexchange.com/oauth/access_token",
            resource_endpoint="https://api.stackexchange.com/2.0",
            redirect_uri="http://localhost/login/stackexchange",
            client_id=config["stackexchange.client_id"],
            client_secret=config["stackexchange.client_secret"])

        c.request_token(code=data["code"],
            parser = lambda data: dict(parse_qsl(data)))

        self.dump_client(c)
        data = c.request("/me", qs={
            "site": "stackoverflow.com",
            "key": config["stackexchange.key"]
            }, parser=lambda c: loads(self.__gunzip(c)))["items"][0]

        self.dump_response(data)
开发者ID:Raekkeri,项目名称:sanction,代码行数:19,代码来源:server.py


注:本文中的sanction.client.Client.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。