I am looking to pull data from a Google Spreadsheet using SpreadAPI.
This is my current code.
$request = new WP_REST_Request('POST', '');
$request->setBody('{\n"method": "GET",\n"sheet": "date",\n"key": "ACCESS_KEY"\n}');
$response = rest_do_request( $request );
However I'm clearly doing something wrong when it comes to formatting the setBody option. I'm not getting a json response, and I can't seem to find any examples of this in the WordPress documentation.
The call works fine when I put it into the RAW section in Postman like this. I'm just not sure how to do that using WordPress.
{
"method": "GET",
"sheet": "date",
"key": "ACCESS_KEY"
}
I am looking to pull data from a Google Spreadsheet using SpreadAPI.
This is my current code.
$request = new WP_REST_Request('POST', 'https://script.google/macros/s/UNIQUE_CODE/exec');
$request->setBody('{\n"method": "GET",\n"sheet": "date",\n"key": "ACCESS_KEY"\n}');
$response = rest_do_request( $request );
However I'm clearly doing something wrong when it comes to formatting the setBody option. I'm not getting a json response, and I can't seem to find any examples of this in the WordPress documentation.
The call works fine when I put it into the RAW section in Postman like this. I'm just not sure how to do that using WordPress.
{
"method": "GET",
"sheet": "date",
"key": "ACCESS_KEY"
}
Share
Improve this question
asked Feb 5, 2020 at 21:23
Brendan QuigleyBrendan Quigley
131 silver badge5 bronze badges
1 Answer
Reset to default 1WP_Rest_Request
is not a way to make outgoing calls to remote REST APIs, it's a data object core uses to pass around information about an incoming request. It's basically something you recieved, it isn't something you can send.
If you poke your sites REST API with a request, WordPress creates and populates a WP_Rest_Request
object and uses it to help handle the request.
So you cannot use this class to make requests to Google.
For that, you want to use the WP_HTTP APIs, such as wp_remote_get
, or wp_remote_post
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744773962a4592932.html
评论列表(0条)