skip to Main Content

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 AppHttpControllers;

use IlluminateHttpRequest;
use GuzzleHttpClient;
use GuzzleHttpExceptionClientException;

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….

2

Answers


  1. Chosen as BEST ANSWER

    Well, maybe this can help someone, solution to my question:

    In this case use the Http facade:

    <?php
    
    namespace AppHttpControllers;
    
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesHttp;
    
    class AuthsController extends Controller
    {
        
    
        public function SocialAuth(Request $request)
        {
    
            $a = $request->input('auth_code');
    
            // URL
            $apiURL = 'https://business-api.tiktok.com/open_api/v1.3/oauth2/access_token/';
    
            // POST Data
            $postInput = [
                'app_id' => '7112335319877287',
                'secret' => '18f52730856f43ed821187bfa9283794ca360',
                'auth_code' => $a
            ];
    
            // Headers
            $headers = [
                //...
            ];
    
            $response = Http::withHeaders($headers)->post($apiURL, $postInput);
    
            $statusCode = $response->getStatusCode();
            $responseBody = json_decode($response->getBody(), true);
    
            echo $statusCode;  // status code
    
            dd($responseBody); // body response
    
    
        }
    }
    

    Response to my request:

    ^ array:4 [▼
      "code" => 0
      "message" => "OK"
      "request_id" => "202211281314430102451411010AF4A"
      "data" => array:3 [▼
        "access_token" => "fbcaa610339b7aeb39eabf29346d06a4e7fe9"
        "advertiser_ids" => array:1 [▶]
        "scope" => array:18 [▶]
      ]
    ]
    

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

    use GuzzleHttpClient;
    use GuzzleHttpExceptionClientException;
    use IlluminateHttpRequest;
    
    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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search