如何获得扑扑的WordPress帖子

时间:2019-10-21 11:06:46

标签: json wordpress api flutter

我如何在我的移动应用程序中获取帖子信息,该信息是使用flutter从我的网站添加的,并显示在listview中?

访问http://heratexchangeunion.com/wp-json/wp/v2/exchanger

1 个答案:

答案 0 :(得分:0)

您可以使用以下两个插件:

https://pub.dev/packages/flutter_wordpress

https://pub.dev/packages/wordpress_api

代码示例

import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;

wp.WordPress wordPress;

wordPress = wp.WordPress(
  baseUrl: 'http://localhost',
  authenticator: wp.WordPressAuthenticator.JWT,
  adminName: '', 
  adminKey: '',
);

Future<wp.User> response = wordPress.authenticateUser(
  username: 'ChiefEditor',
  password: 'chiefeditor@123',
);

Future<List<wp.Post>> posts = wordPress.fetchPosts(
  params: wp.ParamsPostList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 20,
    order: wp.Order.desc,
    orderBy: wp.PostsOrderBy.date,
  ),
  fetchAuthor: true,
  fetchFeaturedMedia: true,
  fetchComments: true,
);