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


Python httplib2.Http方法代码示例

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


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

示例1: check_connection

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def check_connection(flags=None):
    """ Checks if link to google sheet is correctly set up. """
    try:
        credentials = _get_credentials(flags)
        http = credentials.authorize(httplib2.Http())
        discovery_url = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
        service = discovery.build('sheets', 'v4', http=http, discoveryServiceUrl=discovery_url)

        title_cell = 'B2'
        title_cell_expected_content = 'Logs'

        result = service.spreadsheets().values().get(
            spreadsheetId=_get_spreadsheet_id(), range=title_cell).execute()
        values = result.get('values')
        if not values:
            raise GoogleSheetsAccessFailedException('No values found')
        if values[0][0] != title_cell_expected_content:
            raise GoogleSheetsAccessFailedException('Unexpected content found: {}'.format(values))
        print('Google Sheets connection established')
        return service
    except HttpError as e:
        raise GoogleSheetsAccessFailedException('HttpError: {}'.format(e)) 
开发者ID:fab-jul,项目名称:imgcomp-cvpr,代码行数:24,代码来源:sheets_logger.py

示例2: __init__

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def __init__(self, api):
		self.consumer_key = api["consumer_key"]
		self.consumer_secret = api["consumer_secret"]
		self.access_token = api["access_token"]
		self.token_secret = api["token_secret"]

		bearer_token_credentials = self.consumer_key+':'+self.consumer_secret

		encoded_credentials = base64.b64encode(bearer_token_credentials.encode('utf-8')).decode('utf-8')
		headers = {
			'Authorization': 'Basic ' + encoded_credentials,
			'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
		}
		url = "https://api.twitter.com/oauth2/token/?grant_type=client_credentials"
		http = httplib2.Http()
		response, content = http.request(url, method="POST", headers=headers)
		content = json.loads(content.decode("utf-8"))
		self.bearer_token = content["access_token"] 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:20,代码来源:twitter_api.py

示例3: fetch_tweets_by_topic

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fetch_tweets_by_topic(self, graph, keyword, limit=15):
		url = "https://api.twitter.com/1.1/search/tweets.json?q=" + keyword + "&count=" + str(limit)
		http = httplib2.Http()
		headers = {
			'Authorization': 'Bearer ' + self.bearer_token
		}
		response, content = http.request(url, method="GET", headers=headers)
		result = json.loads(content.decode())
		for tweet in result["statuses"]:
			single_tweet = TwitterTweet(tweet)
			graph.create_node(single_tweet)
			creator = TwitterUser(tweet["user"])
			graph.create_node(creator)
			graph.create_edge(Edge(single_tweet.get_id(), creator.get_id(), "CREATED_BY"))
			graph.create_edge(Edge(creator.get_id(), single_tweet.get_id(), "CREATED"))
			if 'retweeted_status' in tweet:
				original_tweet = TwitterTweet(tweet["retweeted_status"])
				graph.create_node(original_tweet)
				graph.create_edge(Edge(single_tweet.get_id(), original_tweet.get_id(), "RETWEET"))
				graph.create_edge(Edge(original_tweet.get_id(), single_tweet.get_id(), "RETWEETED BY"))
			if 'quoted_status' in tweet:
				original_tweet = TwitterTweet(tweet["quoted_status"])
				graph.create_node(original_tweet)
				graph.create_edge(Edge(single_tweet.get_id(), original_tweet.get_id(), "QUOTE"))
				graph.create_edge(Edge(original_tweet.get_id(), single_tweet.get_id(), "QUOTED BY")) 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:27,代码来源:twitter_api.py

示例4: fecth_friends_by_screenname

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fecth_friends_by_screenname(self, graph, screenname, limit=15):
		user = self.get_single_user_by_screenname(graph, screenname)
		graph.create_node(user)

		url = "https://api.twitter.com/1.1/friends/list.json?screen_name=" + screenname + "&count=" + str(limit)
		http = httplib2.Http()
		headers = {
			'Authorization': 'Bearer ' + self.bearer_token
		}
		response, content = http.request(url, method="GET", headers=headers)
		result = json.loads(content.decode())

		for friend in result["users"]:
			single_friend = TwitterUser(friend)
			graph.create_node(single_friend)
			graph.create_edge(Edge(single_friend.get_id(), user.get_id(), "FRIEND WITH"))
			graph.create_edge(Edge(user.get_id(), single_friend.get_id(), "FRIEND WITH")) 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:19,代码来源:twitter_api.py

示例5: __init__

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def __init__(self, api):
        self.client_id = api["client_id"]
        self.client_secret = api["client_secret"]
        self.user_agent = api["user_agent"]

        self.h = httplib2.Http(".cache")
        self.h.add_credentials(self.client_id, self.client_secret)
        resp, content = self.h.request(
            "https://www.reddit.com/api/v1/access_token/?grant_type=password&username=" +
            api["username"]+"&password="+api["password"],
            "POST"
        )

        content = json.loads(content.decode("utf-8"))

        self.headers = {
            "Authorization": "bearer " + content["access_token"],
            "User-Agent": self.user_agent
        } 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:21,代码来源:reddit_api.py

示例6: fetch_pinterest_my_boards

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fetch_pinterest_my_boards(self, graph):
        url = "https://api.pinterest.com/v1/me/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Cbio%2Caccount_type%2Ccounts%2Ccreated_at%2Cimage%2Cusername"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())
        user = PinterestUser(result["data"])
        graph.create_node(user)

        url = "https://api.pinterest.com/v1/me/boards/?access_token=" + self.access_token + \
            "&fields=id%2Cname%2Curl%2Ccounts%2Ccreated_at%2Ccreator%2Cdescription%2Cimage%2Cprivacy"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())

        for myboard in result["data"]:
            board = PinterestBoard(myboard)
            graph.create_node(board)
            graph.create_edge(Edge(board.get_id(), user.get_id(), "CREATED_BY"))
            graph.create_edge(Edge(user.get_id(), board.get_id(), "CREATED"))



    # get the graph of my pins 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:26,代码来源:pinterest_api.py

示例7: fetch_pinterest_my_pins

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fetch_pinterest_my_pins(self, graph):
        url = "https://api.pinterest.com/v1/me/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Cbio%2Caccount_type%2Ccounts%2Ccreated_at%2Cimage%2Cusername"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())
        user = PinterestUser(result["data"])
        graph.create_node(user)

        url = "https://api.pinterest.com/v1/me/pins/?access_token=" + self.access_token + \
            "&fields=id%2Clink%2Cnote%2Curl%2Cattribution%2Cboard%2Ccolor%2Coriginal_link%2Ccounts%2Ccreated_at%2Ccreator%2Cimage%2Cmedia"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())

        for mypin in result["data"]:
            pin = PinterestPin(mypin)
            graph.create_node(pin)
            graph.create_edge(Edge(pin.get_id(), user.get_id(), "CREATED_BY"))
            graph.create_edge(Edge(user.get_id(), pin.get_id(), "CREATED"))



    # get the graph of my followers 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:26,代码来源:pinterest_api.py

示例8: fetch_pinterest_my_followers

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fetch_pinterest_my_followers(self, graph):
        url = "https://api.pinterest.com/v1/me/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Caccount_type%2Cusername%2Cbio%2Ccounts%2Ccreated_at%2Cimage"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())
        user = PinterestUser(result["data"])
        graph.create_node(user)

        url = "https://api.pinterest.com/v1/me/followers/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Caccount_type%2Cusername%2Cbio%2Ccounts%2Ccreated_at%2Cimage"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())

        for myfollower in result["data"]:
            follower = PinterestUser(myfollower)
            graph.create_node(follower)
            graph.create_edge(Edge(user.get_id(), follower.get_id(), "FOLLOWED_BY"))



    # get the graph of my following users 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:25,代码来源:pinterest_api.py

示例9: fetch_pinterest_my_following_users

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def fetch_pinterest_my_following_users(self, graph):
        url = "https://api.pinterest.com/v1/me/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Caccount_type%2Cusername%2Cbio%2Ccounts%2Ccreated_at%2Cimage"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())
        user = PinterestUser(result["data"])
        graph.create_node(user)

        url = "https://api.pinterest.com/v1/me/following/users/?access_token=" + self.access_token + \
            "&fields=first_name%2Cid%2Clast_name%2Curl%2Caccount_type%2Cusername%2Cbio%2Ccounts%2Ccreated_at%2Cimage"
        http = httplib2.Http()
        response, content = http.request(url, method="GET")
        result = json.loads(content.decode())

        for myfollowing in result["data"]:
            following = PinterestUser(myfollowing)
            graph.create_node(following)
            graph.create_edge(Edge(user.get_id(), following.get_id(), "FOLLOWING"))



    # get the graph of my following boards 
开发者ID:shobeir,项目名称:GraphiPy,代码行数:25,代码来源:pinterest_api.py

示例10: _refresh_google_token

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def _refresh_google_token():
        with GoogleSheet._client_lock():
            def _():
                import httplib2

                http = httplib2.Http()
                GoogleSheet.g_client.auth.refresh(http)
                GoogleSheet.g_client.session.headers.update({
                    'Authorization': 'Bearer %s' % GoogleSheet.g_client.auth.access_token
                })

            try:
                await asyncio.get_event_loop().run_in_executor(None, _)
            except:
                GoogleSheet._client_initializing = False
                raise
        log.info("Refreshed google token") 
开发者ID:avrae,项目名称:avrae,代码行数:19,代码来源:gsheet.py

示例11: __init__

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def __init__(self, config=None, proxy_config=None):
        self.config = config
        self.client = None
        if proxy_config and 'host' in proxy_config and 'port' in proxy_config:
            proxy_info = ProxyInfo(socks.PROXY_TYPE_HTTP_NO_TUNNEL,
                                   proxy_config['host'], proxy_config['port'])
        else:
            proxy_info = None
        self.http = Http(proxy_info=proxy_info)
        self.var_dir = self.config['var_dir']
        if not exists(self.var_dir):
            makedirs(self.var_dir)
        self.history_id_f = join(self.var_dir, 'gmail_last_history_id')
        if exists(self.history_id_f):
            with open(self.history_id_f) as fh:
                logger.info('Loaded last gmail history id %d', int(fh.read()))
        else:
            # store an invalid id, which will get renewed on next push event
            self.save_last_history_id('1') 
开发者ID:linkedin,项目名称:iris-relay,代码行数:21,代码来源:gmail.py

示例12: get_oauth2_creds

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def get_oauth2_creds():
  '''Generates user credentials.
  
  Will prompt the user to authorize the client when run the first time.
  Saves the credentials in ~/bigquery_credentials.dat.
  '''
  flow  = flow_from_clientsecrets('edx2bigquery-client-key.json',
                                  scope=BIGQUERY_SCOPE)
  storage = Storage(os.path.expanduser('~/bigquery_credentials.dat'))
  credentials = storage.get()
  if credentials is None or credentials.invalid:
    flags = tools.argparser.parse_args([])
    credentials = tools.run_flow(flow, storage, flags)
  else:
    # Make sure we have an up-to-date copy of the creds.
    credentials.refresh(httplib2.Http())
  return credentials 
开发者ID:mitodl,项目名称:edx2bigquery,代码行数:19,代码来源:auth.py

示例13: oauth_token

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def oauth_token(self):
        # The google api and oauth2client libraries use httplib2 instead of
        # requests. Unfortunately httplib2 is terrible (not thread safe, no
        # streaming interface) so we just grab the access_token from the
        # credentials object and use it directly in the requests library anyway.
        max_lifetime = (service_account_module.ServiceAccountCredentials.
                        MAX_TOKEN_LIFETIME_SECS)

        # Refresh token at least this often.
        if (self._oauth_token is None or
            self._oauth_token_age < time.time() - max_lifetime / 2):
            credentials = (service_account_module.
                           ServiceAccountCredentials.
                           from_json_keyfile_dict(
                               self.to_primitive(False),
                               scopes=self._scopes))

            # Its ok to use httplib2 just for refreshing the tokens.
            http = httplib2.Http()
            credentials.refresh(http)

            self._oauth_token = credentials.access_token
            self._oauth_token_age = time.time()

        return self._oauth_token 
开发者ID:google,项目名称:rekall,代码行数:27,代码来源:cloud.py

示例14: _refresh

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def _refresh(self, http_request):
    """Refreshes the access_token.

    Since the underlying App Engine app_identity implementation does its own
    caching we can skip all the storage hoops and just to a refresh using the
    API.

    Args:
      http_request: callable, a callable that matches the method signature of
        httplib2.Http.request, used to make the refresh request.

    Raises:
      AccessTokenRefreshError: When the refresh fails.
    """
    try:
      scopes = self.scope.split()
      (token, _) = app_identity.get_access_token(
          scopes, service_account_id=self.service_account_id)
    except app_identity.Error as e:
      raise AccessTokenRefreshError(str(e))
    self.access_token = token 
开发者ID:mortcanty,项目名称:earthengine,代码行数:23,代码来源:appengine.py

示例15: request

# 需要导入模块: import httplib2 [as 别名]
# 或者: from httplib2 import Http [as 别名]
def request(self, action, params=None, timeout=None):
        body = {"action": action}
        if params:
            body["params"] = params
        body = json.dumps(body)
        h = httplib2.Http(
            timeout=timeout, proxy_info=None
        )  # httplib does not like os.fork
        logger.trace("M2EE request body: %s" % body)
        (response_headers, response_body) = h.request(
            self._url, "POST", body, headers=self._headers
        )
        if response_headers["status"] == "200":
            logger.trace("M2EE response: %s" % response_body)
            return M2EEResponse(
                action, json.loads(response_body.decode("utf-8"))
            )
        else:
            logger.error(
                "non-200 http status code: %s %s"
                % (response_headers, response_body)
            ) 
开发者ID:mendix,项目名称:cf-mendix-buildpack,代码行数:24,代码来源:client.py


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