complete guide for wordpress rest api ??
-
hello everybody
I’ve searched a lot how to use the api in wordpress but I didn’t find a real guide step by step for newbies such as me
I’m feeling lost and don’t know where I can start from.
for few months ago I worked on a project to publish tweets on twitter and found a lot of projects on github doning the same function so I made an useful app can do everything I need.
but when I’ve searched for wordpress projects I haven’t found a project start from zero step to publish the post!
as I’ve learned, I have to make an app to get something as access token to be able to use the api
please help me with a real guide and best small project in php can do what I need
I need it so much please help
thanks so much
The blog I need help with is: (visible only to logged in users)
-
after searching I’ve found WordPress.com Connect.
So I’ve applied everything and get the message “Connection successful!” when callback but when I try to get access_token key, I get a server message:
Notice: Trying to get property of non-object in C:wampwwwwordpresscallback.php on line 42
here is defines.php:
define( 'CLIENT_ID', "XXXXXX" ); define( 'CLIENT_SECRET', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' ); define( 'LOGIN_URL', 'https://engnajjar.wordpress.com/wp-admin/' ); define( 'REDIRECT_URL', 'http://127.0.0.1/wordpress/callback.php' ); // You do not need to change these settings define( 'REQUEST_TOKEN_URL', 'https://public-api.wordpress.com/oauth2/token' ); define( 'AUTHENTICATE_URL', 'https://public-api.wordpress.com/oauth2/authenticate' );here is callback.php:
require_once dirname( __FILE__ ) . '/defines.php'; // If someone visits this page without a <code>code</code> value, it's likely they've not // been authenticated or declined access, so redirect them to the login page. if ( ! isset( $_GET[ 'code' ] ) ) { header( 'Location: ' . LOGIN_URL ); die(); } // We pass an anti-forgery state value when redirecting the visitor, so upon // arrival here, we verify that the returned value matches our expectations. session_start(); if ( $_GET[ 'state' ] !== $_SESSION[ 'wpcc_state' ] ) { die( 'Warning! State mismatch. Authentication attempt may have been compromised.' ); } // When redirected, a temporary, time-sensitive code will be included as a // query parameter. This needs to be exchanged for an authorization token. $code = $_GET[ 'code' ]; $curl = curl_init( REQUEST_TOKEN_URL ); curl_setopt( $curl, CURLOPT_POST, true ); curl_setopt( $curl, CURLOPT_POSTFIELDS, array( 'client_id' => CLIENT_ID, 'redirect_uri' => REDIRECT_URL, 'client_secret' => CLIENT_SECRET, 'code' => $code, 'grant_type' => 'authorization_code' ) ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); $auth = curl_exec( $curl ); // The JSON response can be decoded to an object containing the access_token // that you will use to query the users profile information. $secret = json_decode( $auth ); echo 'Connection successful!';if I add this line:
$access_key = $secret->access_token;I get the previous server message
how to continue please ?
-
Hi there,
This support forum provides support for end-users of free WordPress.com sites. We do not provide API support here.
You can find our API documentation for the WordPress.com API at the following link:
https://developer.wordpress.com/docs/api/
For help with that API you can use the contact form at https://developer.wordpress.com/contact/, but we do not provide in-depth support with using the API.
If you’re looking for information on the REST API in WordPress Core, you can find that here:
https://developer.wordpress.org/rest-api/
For help with the coding aspect of using either API, I suggest you ask in a developer forum instead, like the WordPress StackExchange:
-
- The topic ‘complete guide for wordpress rest api ??’ is closed to new replies.