MCPcopy
hub / github.com/tornadoweb/tornado / twitter_request

Method twitter_request

tornado/auth.py:760–830  ·  view source on GitHub ↗

Fetches the given API path, e.g., ``statuses/user_timeline/btaylor`` The path should not include the format or API version number. (we automatically use JSON format and API version 1). If the request is a POST, ``post_args`` should be provided. Query string argument

(
        self,
        path: str,
        access_token: Dict[str, Any],
        post_args: Optional[Dict[str, Any]] = None,
        **args: Any,
    )

Source from the content-addressed store, hash-verified

758 self._on_request_token(self._OAUTH_AUTHENTICATE_URL, None, response)
759
760 async def twitter_request(
761 self,
762 path: str,
763 access_token: Dict[str, Any],
764 post_args: Optional[Dict[str, Any]] = None,
765 **args: Any,
766 ) -> Any:
767 """Fetches the given API path, e.g., ``statuses/user_timeline/btaylor``
768
769 The path should not include the format or API version number.
770 (we automatically use JSON format and API version 1).
771
772 If the request is a POST, ``post_args`` should be provided. Query
773 string arguments should be given as keyword arguments.
774
775 All the Twitter methods are documented at http://dev.twitter.com/
776
777 Many methods require an OAuth access token which you can
778 obtain through `~OAuthMixin.authorize_redirect` and
779 `~OAuthMixin.get_authenticated_user`. The user returned through that
780 process includes an 'access_token' attribute that can be used
781 to make authenticated requests via this method. Example
782 usage:
783
784 .. testcode::
785
786 class MainHandler(tornado.web.RequestHandler,
787 tornado.auth.TwitterMixin):
788 @tornado.web.authenticated
789 async def get(self):
790 new_entry = await self.twitter_request(
791 "/statuses/update",
792 post_args={"status": "Testing Tornado Web Server"},
793 access_token=self.current_user["access_token"])
794 if not new_entry:
795 # Call failed; perhaps missing permission?
796 await self.authorize_redirect()
797 return
798 self.finish("Posted a message!")
799
800 .. versionchanged:: 6.0
801
802 The ``callback`` argument was removed. Use the returned
803 awaitable object instead.
804 """
805 if path.startswith("http:") or path.startswith("https:"):
806 # Raw urls are useful for e.g. search which doesn't follow the
807 # usual pattern: http://search.twitter.com/search.json
808 url = path
809 else:
810 url = self._TWITTER_BASE_URL + path + ".json"
811 # Add the OAuth resource request signature if we have credentials
812 if access_token:
813 all_args = {}
814 all_args.update(args)
815 all_args.update(post_args or {})
816 method = "POST" if post_args is not None else "GET"
817 oauth = self._oauth_request_parameters(

Callers 2

getMethod · 0.80

Calls 3

get_auth_http_clientMethod · 0.45
fetchMethod · 0.45

Tested by 1

getMethod · 0.64