You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

FSUInnovation's avatar
FSUInnovation
Explorer | Level 4
5 years ago

header array invalid request for token auth php

I have been trying to get the header array for my php curl working. This is the structure of it. $http_headers = array( "Authorization: " . base64_encode($app_key . ":" . $app_secret), "Content-T...
  • Greg-DB's avatar
    Greg-DB
    5 years ago

    You should send them as POST parameters, encoded using "application/x-www-form-urlencoded", not headers. Here's a basic example I just put together for calling /oauth2/token using curl in PHP:

    $app_key = "<APP_KEY>";
    $app_secret = "<APP_SECRET>";
    
    $headers = array("Authorization: Basic " . base64_encode($app_key . ":" . $app_secret),
                     "Content-Type: application/x-www-form-urlencoded");
    
    $authorization_code = "<AUTHORIZATION_CODE>";
    $redirect_uri = "<REDIRECT_URI>";
    
    $params = array("code" => $authorization_code,
                    "grant_type" => "authorization_code",
                    "redirect_uri" => $redirect_uri);
    
    $ch = curl_init('https://api.dropboxapi.com/oauth2/token');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    
    echo $response;
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    
    curl_close($ch);