def make_api_call(self, kind, url, token, method="GET", **kwargs):
        if isinstance(token, OAuth20Token):
            request_kwargs = dict(method=method)
            if method == "POST":
                params = {
                    "access_token": str(token),
                }
                params.update(kwargs["params"])
                request_kwargs["body"] = urllib.urlencode(params)
            else:
                url += "?%s" % urllib.urlencode(dict(access_token=str(token)))
            http = httplib2.Http()
            response, content = http.request(url, **request_kwargs)
        else:
            if isinstance(token, basestring):
                token = oauth.Token.from_string(token)
            client = Client(self.consumer, token=token)
            # @@@ LinkedIn requires Authorization header which is supported in
            # sub-classed version of Client (originally from oauth2)
            request_kwargs = dict(method=method, force_auth_header=True)
            if method == "POST":
                request_kwargs["body"] = urllib.urlencode(kwargs["params"])
            response, content = client.request(url, **request_kwargs)
        if response["status"] == "401":
            raise NotAuthorized()
        if not content:
            raise ServiceFail("no content")
        logger.debug("response: %r" % response)
        logger.debug("content: %r" % content)
        if kind == "raw":
            return content
        elif kind == "json":
            try:
                return json.loads(content)
            except ValueError:
                # @@@ might be better to return a uniform cannot parse
                # exception and let caller determine if it is service fail
                raise ServiceFail("JSON parse error")
        elif kind == "xml":
            return etree.ElementTree(etree.fromstring(content))
        else:
            raise Exception("unsupported API kind")
dataset/ETHPy150Open eldarion/django-oauth-access/oauth_access/access.py/OAuthAccess.make_api_call/original