Getting access token using curl
Hi Guys,
It's my first time using box api, i'm currently stucked in this problem. I was already able to get authorization from the user and I already have a code value. What i'm trying to do is to get the access token of the user using curl since box has no api for php (any suggestion?). Here is my code written in php
$code = $_GET['code']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.box.com/oauth2/token"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=$code&client_id=$client_id&client_secret=>$client_secret"); curl_setopt($ch, CURLOPT_POST, 1); $headers = array(); $headers[] = "Content-Type: application/x-www-form-urlencoded"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else{ die(var_dump($result)); }
Luckily there is no error in the curl execution but sadly the response of the curl goes something like this.
'{"error":"invalid_client","error_description":"The client credentials are invalid"}
Any idea on this? Would appreciate your help.
Thanks! 🙂
-
Hi ,
Off hand I don't see anything specific in the sample. I would just make double check that the data sent via the post fields is accurate.
Here are some alternate options. There are a number of PHP SDKs created by the community for Box. Here are a few recent ones:
https://github.com/maengkom/boxapi
https://github.com/stevenmaguire/oauth2-box
Both implement some version of the OAuth 2 implementation that should be able to help.
- Jon
Please sign in to leave a comment.
Comments
1 comment