简体   繁体   中英

WP REST API, no data is fetched

I'm totally new this API, OAuth stuff in WordPress and I'm trying to list all the users as a JSON and make them usable in a client app.

What I did was installing this little plugin WP REST API (WP API) and trying to list a user via the address mysite.com/wp-json/users/4 . But, it just gives me this message

[{"code":"json_user_cannot_list","message":"Sorry, you are not allowed to list users."}]

I did changed Permalinks too. But no luck!

What's wrong in this ?

根据其文档,您使用的是哪个版本的插件,版本 2 可以访问这样的文件

使用链接为https://wordpress.org/plugins/rest-api/ 的版本 2 这将启用查询方式。您也可以阅读版本 1 描述以了解更多详细信息

implement get_user() method of WP_REST_CONTROLLER

protected function get_user() {

        $error = new WP_Error(
            'rest_user_invalid_id',
            __( 'Invalid user ID.' ),
            array( 'status' => 404 )
        );

        // if ( (int) $id <= 0 ) {
        //  return $error;
        // }

        // $user = get_userdata($user_email);
        // if ( empty( $user ) || ! $user->exists() ) {
        //  return $error;
        // }

        // if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) {
        //  return $error;
        // }

        return $user;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM