User details

The user has now authorized access to their Twitter account. The access_token is specific to the user so anytime you want to act as the user create a TwitterOAuth instance and start making requests.

Credential storage

Pull the long-lived credentials out of storage. This example uses basic PHP sessions but your implementation should use a database like PostgreSQL/MongoDB/etc.

$access_token = $_SESSION['access_token'];

Authenticated requests

Now we make a TwitterOAuth instance with the users access_token.

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

Get account details

At this point we will use the access token that is authorized to act as the user, to get their account details.

Request
$user = $connection->get('account/verify_credentials', ['tweet_mode' => 'extended', 'include_entities' => 'true']);
Response Cached
{"id"=>12, "id_str"=>"12", "name"=>"jack", "screen_name"=>"jack", "location"=>"", "profile_location"=>nil, "description"=>"#bitcoin", "url"=>nil, "entities"=>{"description"=>{"urls"=>[]}}, "protected"=>false, "followers_count"=>5033667, "friends_count"=>4510, "listed_count"=>28022, "created_at"=>"Tue Mar 21 20:50:14 +0000 2006", "favourites_count"=>31461, "utc_offset"=>nil, "time_zone"=>nil, "geo_enabled"=>true, "verified"=>true, "statuses_count"=>27342, "lang"=>nil, "status"=>{"created_at"=>"Sat Dec 26 00:21:17 +0000 2020", "id"=>1342626501238276096, "id_str"=>"1342626501238276096", "full_text"=>"RT @PowerDNS_Bert: In this post, we'll reverse-engineer the actual mRNA code of the @BioNTech_Group/@pfizer SARS-CoV-2 vaccine, character f…", "truncated"=>false, "display_text_range"=>[0, 140], "entities"=>{"hashtags"=>[], "symbols"=>[], "user_mentions"=>[{"screen_name"=>"PowerDNS_Bert", "name"=>"Bert Hubert 🇩🇪🇺🇸", "id"=>185980279, "id_str"=>"185980279", "indices"=>[3, 17]}, {"screen_name"=>"BioNTech_Group", "name"=>"BioNTech SE", "id"=>1060984350995550208, "id_str"=>"1060984350995550208", "indices"=>[84, 99]}, {"screen_name"=>"pfizer", "name"=>"Pfizer Inc.", "id"=>56488059, "id_str"=>"56488059", "indices"=>[100, 107]}], "urls"=>[]}, "source"=>"Twitter for iPhone", "in_reply_to_status_id"=>nil, "in_reply_to_status_id_str"=>nil, "in_reply_to_user_id"=>nil, "in_reply_to_user_id_str"=>nil, "in_reply_to_screen_name"=>nil, "geo"=>nil, "coordinates"=>nil, "place"=>nil, "contributors"=>nil, "retweeted_status"=>{"created_at"=>"Fri Dec 25 20:30:45 +0000 2020", "id"=>1342568484946010116, "id_str"=>"1342568484946010116", "full_text"=>"In this post, we'll reverse-engineer the actual mRNA code of the @BioNTech_Group/@pfizer SARS-CoV-2 vaccine, character for character. And along the way, this will also explain how the vaccine works. Surprisingly, there are some fun mysteries in there!\nhttps://t.co/HbjPFUXHUG", "truncated"=>false, "display_text_range"=>[0, 275], "entities"=>{"hashtags"=>[], "symbols"=>[], "user_mentions"=>[{"screen_name"=>"BioNTech_Group", "name"=>"BioNTech SE", "id"=>1060984350995550208, "id_str"=>"1060984350995550208", "indices"=>[65, 80]}, {"screen_name"=>"pfizer", "name"=>"Pfizer Inc.", "id"=>56488059, "id_str"=>"56488059", "indices"=>[81, 88]}], "urls"=>[{"url"=>"https://t.co/HbjPFUXHUG", "expanded_url"=>"https://berthub.eu/articles/posts/reverse-engineering-source-code-of-the-biontech-pfizer-vaccine/", "display_url"=>"berthub.eu/articles/posts…", "indices"=>[252, 275]}]}, "source"=>"Twitter Web App", "in_reply_to_status_id"=>nil, "in_reply_to_status_id_str"=>nil, "in_reply_to_user_id"=>nil, "in_reply_to_user_id_str"=>nil, "in_reply_to_screen_name"=>nil, "geo"=>nil, "coordinates"=>nil, "place"=>nil, "contributors"=>nil, "is_quote_status"=>false, "retweet_count"=>3680, "favorite_count"=>7866, "favorited"=>false, "retweeted"=>false, "possibly_sensitive"=>false, "lang"=>"en"}, "is_quote_status"=>false, "retweet_count"=>3680, "favorite_count"=>0, "favorited"=>false, "retweeted"=>false, "lang"=>"en"}, "contributors_enabled"=>false, "is_translator"=>false, "is_translation_enabled"=>false, "profile_background_color"=>"EBEBEB", "profile_background_image_url"=>"http://abs.twimg.com/images/themes/theme7/bg.gif", "profile_background_image_url_https"=>"https://abs.twimg.com/images/themes/theme7/bg.gif", "profile_background_tile"=>false, "profile_image_url"=>"http://pbs.twimg.com/profile_images/1661201415899951105/azNjKOSH_normal.jpg", "profile_image_url_https"=>"https://pbs.twimg.com/profile_images/1661201415899951105/azNjKOSH_normal.jpg", "profile_banner_url"=>"https://pbs.twimg.com/profile_banners/12/1688241283", "profile_link_color"=>"990000", "profile_sidebar_border_color"=>"DFDFDF", "profile_sidebar_fill_color"=>"F3F3F3", "profile_text_color"=>"333333", "profile_use_background_image"=>true, "has_extended_profile"=>true, "default_profile"=>false, "default_profile_image"=>false, "following"=>false, "follow_request_sent"=>false, "notifications"=>false, "translator_type"=>"regular"}

You now have the authenticated user's Twitter account details.