Logging in with an account
How to obtain authorization from a user and perform actions on their behalf.
Last updated
Was this helpful?
How to obtain authorization from a user and perform actions on their behalf.
Last updated
Was this helpful?
When we registered our app and when we will authorize our user, we need to define what exactly our generated token will have permission to do. This is done through the use of OAuth scopes. Each API method has an associated scope, and can only be called if the token being used for authorization has been generated with the corresponding scope.
Scopes must be a subset. When we created our app, we specified read write follow push
-- we could simply request all available scopes by specifying read write follow push
, but it is a better idea to only request what your app will actually need through granular scopes. See for a full list of scopes. Each API method's documentation will also specify the OAuth access level and scope required to call it.
This is similar to the authentication flow from before, but this time, we need to obtain authorization from a user as well.
First, if you have not already registered a client application, then see on the previous page or go directly to for the full documentation of that method. We will need the client_id
and client_secret
for our application.
To authorize a user, request in a browser with the following query parameters:
Note the following:
client_id
and client_secret
were obtained when registering our application.
redirect_uri
is one of the URIs we registered with our app. We are still using "out of band" for this example, which means we will have to manually copy and paste the resulting code, but if you registered your application with a URI that you control, then the code will be returned as a query parameter code
and can be logged by your request handler. See the response section of the API method documentation for more information on this.
Note the following:
client_id
and client_secret
were provided in the response text when you registered your application.
redirect_uri
must be one of the URIs defined when registering the application.
We are requesting a grant_type
of authorization_code
, which still defaults to giving us the read
scope. However, while authorizing our user, we requested a certain scope
-- pass the exact same value here.
With our OAuth token for the authorized user, we can now perform any action as that user that is within our token's scope.
scope
must be a subset of our registered app's registered scopes. It is a good idea to only request what you need. See for more information.
Now that we have an authorization code
, let's obtain an access token that will authenticate our requests as the authorized user. To do so, use like before, but pass the authorization code we just obtained:
The code
can only be used once. If you need to obtain a new token, you will need to have the user authorize again by repeating the above step.
The response of this method is a entity. We will need the access_token
value. Once you have the access token, save it in your local cache. To use it in requests, add the HTTP header Authorization: Bearer ...
to any API call that requires OAuth (i.e., one that is not publicly accessible). Let's verify that our obtained credentials are working by calling :
If we've obtained our token and formatted our request correctly, we should see our details returned to us as an entity, with the source
parameter included.
See for how to create statuses.
See for creating media attachments.
See for managing scheduled statuses.
See for accessing timelines.
See for saving and loading positions in timelines.
See for performing actions on statuses.
See for viewing and voting on polls.
See for obtaining list IDs to use with .
See for obtaining direct conversations.
See for listing favourites.
See for listing bookmarks.
See for performing actions on other users.
See for handling follow requests.
See for listing mutes.
See for listing blocks.
See for managing a user's notifications.
See for subscribing to push notifications.
See for querying resources.
See for suggested accounts to follow.
See for managing filtered keywords.
See for managing blocked domains.
See for creating reports.
See for moderator actions.
See for managing a user profile's featured accounts.
See for managing a user profile's featured hashtags.
See for reading user preferences.