Getting bearer token
-
Hello,
I am trying to get a bearer token to use the stas api. I have made this step successfully:
1. Registered my app
2. Retrieved the code with:https://public-api.wordpress.com/oauth2/authorize?client_id=your_client_id&redirect_uri=your_url&response_type=code&blog=1234
3. But I am having troubles with the Server / Code Authentication. I am using this code:$curl = curl_init( 'https://public-api.wordpress.com/oauth2/token' ); curl_setopt( $curl, CURLOPT_POST, true ); curl_setopt( $curl, CURLOPT_POSTFIELDS, array( 'client_id' => your_client_id, 'redirect_uri' => your_redirect_url, 'client_secret' => your_client_secret_key, 'code' => $_GET['code'], // The code from the previous request 'grant_type' => 'authorization_code' ) ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1); $auth = curl_exec( $curl ); $secret = json_decode($auth); $access_key = $secret->access_token;I have a doubt, where it says:”// The code from the previous request”, what should I replace? Should I replace the: “[‘code’]”? And with that should I replace it? With this whole thing “https://developer.wordpress.com/?code=cw9hk1xG9k” or just with: “cw9hk1xG9k”?
I have tried pasting that code in a php file, but when I run it on a php server it returns nothing, a blank html. I was expecting this:
{ "access_token": "YOUR_API_TOKEN", "blog_id": "blog ID", "blog_url": "blog url", "token_type": "bearer" }Thanks in advance.
Regards,
DanielThe blog I need help with is: (visible only to logged in users)
-
Hi Daniel,
To provide you with the most complete answer, I’ve sent you a private response via email to the email address set on your WordPress.com account.
Cheers
- The topic ‘Getting bearer token’ is closed to new replies.