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