laravelguzzletiktok-api

Missing fields error when making a post request in Laravel


I am making a post request to the tiktok API, entering the 3 parameters that are requested, but when I carry out the request, it shows me the following: "Required fields are missing: app_id is required.", I attach an image:

enter image description here

but when performing the same procedure in postman if I have a positive response.

here is my code:

my route:

Route::get('callback-tiktok', [AuthsController::class, 'SocialAuth']);

my controller:

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class AuthsController extends Controller
{

    public function SocialAuth(Request $request)
    {
        $a = $request->input('auth_code');
        // create a guzzle client object here
        $client = new Client();
        $respuesta = $this->client->request(
            'POST',
            'https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/',
            [
                'form_params' => [
                    'app_id' => '7112335319877287937',
                    'secret' => '18f52730856f43ed821187bfa9283794ca360ef1',
                    'auth_code' => $a
                ],
                'headers'  =>  [
                    'Content-Type'      =>  'application /json'
                ],
            ]
        );
        return response()->json($respuesta->getBody()->getContents());
    }
}

When compiling I get the following:

The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/epgutp/tiktok/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file....


Solution

  • I guess, you made some couple of errors, try this:

    use GuzzleHttp\Client;
    use GuzzleHttp\Exception\ClientException;
    use Illuminate\Http\Request;
    
    class AuthsController extends Controller
    {
        public function SocialAuth(Request $request)
        {
            $a = $request->input('auth_code');
            // create a guzzle client object here
            $client = new Client();
            $respuesta = $this->client->request('POST', 
                  'https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/',
                 [
                  'form_params' => [
                    'app_id' => '711233531987728793',
                    'secret' => '18f52730856f43ed821187bfa9283794ca360ef',
                    'auth_code' => $a
                  ], 
                  'headers'  =>  [
                    'Content-Type'      =>  'application /json'
                  ],
              ]);
             return response()->json($respuesta->getBody()->getContents());
            
        }
    
    }
    
    

    Applying this solution gives me the following error:

    enter image description here