title: How to send request to Twitter api using access token in ASP.NET core?
body: <p>I'm working on a project which is receiving the access-token from the Front-end  client and using that access token I have to make request to Twitter API in order to get the user details including email address and profile picture url. </p>
  
  <p>in the case of Facebook it is just a normal get request , in the case of Google and Microsoft I just have to add access token as Bearer token in Header but, I'm not able to find a way for Twitter.</p>
  
  <p>This is the url where I have to make request.</p>
  
  <p><a href="https://api.twitter.com/1.1/account/verify_credentials.json" rel="nofollow noreferrer">https://api.twitter.com/1.1/account/verify_credentials.json</a></p>
  
  <p>Here is the code for Facebook , Google and Microsoft.</p>
  
  <pre><code>private async Task&lt;Profile&gt; ProfileAsync(string token,string providerName)
      {
          using (HttpClient client = new HttpClient())
          {
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              if((providerName=="Google") || (providerName=="Microsoft"))
              {
                  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
              }
              var formatters = new List&lt;MediaTypeFormatter&gt;()
              {
                  new JsonMediaTypeFormatter()
              };
              string url;
              Profile profile = null;
              if (providerName=="Facebook")
              {
                   url = $"https://graph.facebook.com/me?fields=id,name,email&amp;access_token={token}";
              }
              else if(providerName=="Google")
              {
                  url = $"https://www.googleapis.com/userinfo/v2/me";
              }
              else if(providerName=="Microsoft")
              {
                  url = $"https://graph.microsoft.com/v1.0/me/";
              }
              else
              {
                  throw new Exception("Unsupported grant type.");
              }
              HttpResponseMessage response = await client.GetAsync(url);
  
              if (response.IsSuccessStatusCode)
              {
                  profile = await response.Content.ReadAsAsync&lt;Profile&gt;(formatters);
              }
              if(providerName=="Microsoft")
              {
                  profile.email = profile.userPrincipalName;
                  profile.name = profile.displayName;
              }
              return profile;
          }
      }
  </code></pre>