<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: George Cojocaru</title>
    <description>The latest articles on DEV Community by George Cojocaru (@george_cojocaru_809bc6b2e).</description>
    <link>https://dev.to/george_cojocaru_809bc6b2e</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3492783%2Fc0b479a0-12a9-4077-808b-901de4e34cb3.png</url>
      <title>DEV Community: George Cojocaru</title>
      <link>https://dev.to/george_cojocaru_809bc6b2e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/george_cojocaru_809bc6b2e"/>
    <language>en</language>
    <item>
      <title>TikTok API</title>
      <dc:creator>George Cojocaru</dc:creator>
      <pubDate>Wed, 10 Sep 2025 16:47:35 +0000</pubDate>
      <link>https://dev.to/george_cojocaru_809bc6b2e/tiktok-api-386o</link>
      <guid>https://dev.to/george_cojocaru_809bc6b2e/tiktok-api-386o</guid>
      <description>&lt;p&gt;Hi! I've got a problem using TikTok API. I get an error about access token which says that is invalid. Here is the method used for getting the token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static String getAccessTokenWithClientCredentials() throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        // The body for the Client Credentials grant is simpler.
        // You only need to identify your client and specify the grant type.
        String form = "client_key=" + URLEncoder.encode(CLIENT_KEY, StandardCharsets.UTF_8)
                + "&amp;amp;client_secret=" + URLEncoder.encode(CLIENT_SECRET, StandardCharsets.UTF_8)
                + "&amp;amp;grant_type=client_credentials";

        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(TOKEN_URL))
                .timeout(Duration.ofSeconds(20))
                .header("Content-Type", "application/x-www-form-urlencoded")
                .POST(HttpRequest.BodyPublishers.ofString(form))
                .build();

        System.out.println("Requesting access token from TikTok API...");
        HttpResponse&amp;lt;String&amp;gt; resp = client.send(req, HttpResponse.BodyHandlers.ofString());

        if (resp.statusCode() != 200) {
            throw new RuntimeException("Token exchange failed: " + resp.statusCode() + " -&amp;gt; " + resp.body());
        }

        JsonNode root = JSON.readTree(resp.body());
        // Note: The response for this grant type also includes other fields like
        // 'scope', 'expires_in', and 'token_type', which you might want to parse.
        return root.get("access_token").asText();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I used the token when calling the API but get the error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; {"error":{"code":"access_token_invalid","message":"The access token is invalid or not found in the request.","log_id":"202509101626444C67AFEEA729D40D3834"},"data":{}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you have this problem? &lt;/p&gt;

</description>
      <category>api</category>
      <category>java</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
