Returns a dict including an authorization URL, ``auth_url``, to direct a user to :param callback_url: (optional) Url the user is returned to after they authorize your app (web clients only) :param force_login: (optional) Forces the user to ent
(self, callback_url=None, force_login=False,
screen_name='')
| 307 | return self._last_call['headers'].get(header, default_return_value) |
| 308 | |
| 309 | def get_authentication_tokens(self, callback_url=None, force_login=False, |
| 310 | screen_name=''): |
| 311 | """Returns a dict including an authorization URL, ``auth_url``, to |
| 312 | direct a user to |
| 313 | |
| 314 | :param callback_url: (optional) Url the user is returned to after |
| 315 | they authorize your app (web clients only) |
| 316 | :param force_login: (optional) Forces the user to enter their |
| 317 | credentials to ensure the correct users |
| 318 | account is authorized. |
| 319 | :param screen_name: (optional) If forced_login is set OR user is |
| 320 | not currently logged in, Prefills the username |
| 321 | input box of the OAuth login screen with the |
| 322 | given value |
| 323 | |
| 324 | :rtype: dict |
| 325 | """ |
| 326 | if self.oauth_version != 1: |
| 327 | raise TwythonError('This method can only be called when your \ |
| 328 | OAuth version is 1.0.') |
| 329 | |
| 330 | request_args = {} |
| 331 | if callback_url: |
| 332 | request_args['oauth_callback'] = callback_url |
| 333 | response = self.client.get(self.request_token_url, params=request_args) |
| 334 | |
| 335 | if response.status_code == 401: |
| 336 | raise TwythonAuthError(response.content, |
| 337 | error_code=response.status_code) |
| 338 | elif response.status_code != 200: |
| 339 | raise TwythonError(response.content, |
| 340 | error_code=response.status_code) |
| 341 | |
| 342 | request_tokens = dict(parse_qsl(response.content.decode('utf-8'))) |
| 343 | if not request_tokens: |
| 344 | raise TwythonError('Unable to decode request tokens.') |
| 345 | |
| 346 | oauth_callback_confirmed = request_tokens.get('oauth_callback_confirmed') \ |
| 347 | == 'true' |
| 348 | |
| 349 | auth_url_params = { |
| 350 | 'oauth_token': request_tokens['oauth_token'], |
| 351 | } |
| 352 | |
| 353 | if force_login: |
| 354 | auth_url_params.update({ |
| 355 | 'force_login': force_login, |
| 356 | 'screen_name': screen_name |
| 357 | }) |
| 358 | |
| 359 | # Use old-style callback argument if server didn't accept new-style |
| 360 | if callback_url and not oauth_callback_confirmed: |
| 361 | auth_url_params['oauth_callback'] = self.callback_url |
| 362 | |
| 363 | request_tokens['auth_url'] = self.authenticate_url + \ |
| 364 | '?' + urlencode(auth_url_params) |
| 365 | |
| 366 | return request_tokens |