a good day,
I'm having trouble getting an access token. I followed the guide here: http://developers.box.com/oauth/
and already get my client_id , client_secret and set redirect_uri in the application settings (OAuth2 parameters).
Here is the code for the client.php file
<?php
$client_id = 'my_client_id_here';
$post_url = 'https://www.box.com/api/oauth2/authorize';
include 'includes/header.php';
?>
<div id="content">
<form action="<?php echo $post_url; ?>" type="POST" enctype="application/x-www-form-urlencoded">
<input type="text" name="response_type" value="code">
<input type="text" name="client_id" value="<?php echo $client_id; ?>">
<input type="text" name="state" value="vexhax97td8xf_SomeTemporaryValueForTesting">
<input type="submit">
</form>
<div id="response"></div>
</div>
<?php
include 'includes/footer.php';
?>
and here is the code for something.php file (here will be < redirect_uri )
<?php
$client_id = 'my_client_id_here';
$client_secret = 'my_client_secrect_here';
$post_url = 'https://www.box.com/api/oauth2/token';
$code = $_GET['code'];
include 'includes/header.php';
$fields_params = array(
"grant_type" => 'authorization_code',
"code" => $code,
"client_id" => $client_id,
"client_secret" => $client_secret
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data, true);
var_dump($json);
?>
<div id="content">
<?php
if (isset($_GET))
var_dump($_GET);
if (isset($_POST))
var_dump($_POST);
?>
</div>
<?php
include 'includes/footer.php';
?>
... now what happens
1.) in the first step ( client.php ), there is a form with a submit button.
2.) After I clicked the submit button, I am redirected to the Box login page with the "Authorize" button.
3.) . redirect_uri, (something.php), curl-, , , :
array(2) { ["error"]=> string(14) "invalid_client" ["error_description"]=> string(34) "The client credentials are invalid" }
, client_id client_secret, . URL- redirect_uri, SSL.
, , ?
.