final private static String apiBaseURL = "https://openapi.smtown.com/api";
final private static String profileEndPoint = "about/me";
final private static String accessToken = "2a324609ec94f18d614d4bc425de754";
public static void main(String[] args){
//implementation 'org.apache.httpcomponents:httpclient'
try (CloseableHttpClient client = HttpClients.createDefault()) {
HttpGet get = new HttpGet(String.format("%s/%s", apiBaseURL, profileEndPoint));
get.setHeader("Authorization", String.format("Bearer %s", accessToken));
try(CloseableHttpResponse response = client.execute(get)){
if(response.getStatusLine().getStatusCode() == 200) {
String responseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
System.out.println(responseData);
}
}
} catch (IOException e){
throw new RuntimeException();
}
}
private readonly string ApiBaseURL = "https://openapi.smtown.com/api";
private readonly string ProfileEndPoint = "about/me";
private readonly string AccessToken = "2a324609ec94f18d614d4bc425de754";
private async void GetAccessToken()
{
using System.Net.Http.HttpClient client = new(); System.Net.Http.HttpRequestMessage tokenRequest = new()
{
Method = HttpMethod.Get,
RequestUri = new Uri(string.Format("{0}/{1}", ApiBaseURL, ProfileEndPoint))
};
tokenRequest.Headers.TryAddWithoutValidation("Authorization", string.Format("Bearer {0}", AccessToken));
var response = await client.SendAsync(tokenRequest);
if (response.IsSuccessStatusCode)
{
var responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseData);
}
}