我使用 Oauth2 与 woocommerse 连接。
但我不能使用过滤器,例如 /wp-json/wp/v2/post&filter[category_name]=food
我获得了有关用户的信息,例如http://my-site/wp-json/wp/v2/users
,但是在页面上我获得了有关前 10 个用户的信息,我需要更多...当我使用过滤器时,例如:http://my-site/wp-json/wp/v2/users?filter[posts_per_page]=5
-过滤器不起作用
我的代码:
require('vendor/autoload.php');
const CLIENT_ID = 'my-ID';
const CLIENT_SECRET = 'my-secret';
const REDIRECT_URI = 'http://wooc/test.php';
const AUTHORIZATION_ENDPOINT = 'http://my-site/oauth/authorize';
const TOKEN_ENDPOINT = 'http://my-site/oauth/token';
$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code']))
{
$auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
header('Location: ' . $auth_url);
die('Redirect');
}
else
{
$params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code',$params);
}
$client->setAccessToken("a6kpdxqqs3runou66ovzjjy54rvfubv64hhpdomn");
$data = $client->fetch("http://my-site/wp-json/wp/v2/users?filter[posts_per_page]=5");
echo "<pre>";
var_dump($data);
我不明白错误在哪里!请帮忙。谢谢你