Bazaarvoice移动sdk提供了对Bazaarvoice提供的大多数核心产品的访问。必威手机版本要了解更多信息,请参阅Mobile SDK文档主页

内容

+显示 ——隐藏

本文档解释了如何使用移动SDK显示消费者生成的内容(CGC),包括评论和统计数据以及产品信息。

简介

使用Bazaarvoice移动sdk来启用对话功能,例如评分和评论。的对话模块提供了易于使用的包装器API的对话.移动SDK支持以下对话显示功能:

你需要你的apiKeyConversations实现和使用移动sdk的对话。

Swift和Objective-C代码演练的完整项目在SDK路径中例子/对话.要获得更全面的对话SDK演示,请参见下面的BVSDKDemo项目/ / BVSDKDemo例子

开始实现此Mobile SDK模块之前,请检查上的步骤来验证您的安装安装页面。

显示内容

显示内容的思想围绕产品展示页面.例如,下面的示例页面使用单个ProductDisplayPageRequest,并显示在BVProductDisplayPageViewController

我们在这里展示了非常常见的内容:平均评分、评论数量和问题/答案数量。在展示完产品展示页面,您可以通过更多分页评论而且问题/答案(下面讨论)。最后,您可以加载大部分评级对于多个产品在同一时间,这必威手机版本是有用的,当显示明星和数量的评论在一个类别页面。

内容类型

如果您需要检查以下API的可能参数列表,请参考以下链接并从部分内容中选择API:

下面的选项卡更详细地描述了可用的内容类型。

正在加载产品显示页面

显示产品显示页面时,使用BVProductDisplayPageRequest获取有用的数据reviewStatistics或者包括前10个BVReview评论。然后,将这些数据显示在指定的BVProductDisplayPageViewController,下面讨论。

首先,让我们看一个简单的BVProductDisplayPageRequest

//请求产品信息,包括评论和问题/答案的统计数据。let request = BVProductDisplayPageRequest(productId: "test1") .includeStatistics(.reviews) .includeStatistics(.questions)
//请求产品信息,包括评论和问题/答案的统计数据。BVProductDisplayPageRequest* request = [[BVProductDisplayPageRequest alloc] initWithProductId:@"test1"];(请求includeStatistics: BVProductIncludeTypeValueReviews);(请求includeStatistics: BVProductIncludeTypeValueQuestions);

在上面的代码中,aProductDisplayPageRequest为productIdtest1.我们还包括评论和问题/答案的统计数据。您可能希望在其中包含一些实际内容,如下所示。我们还根据他们的提交时间对所包含的评论进行排序。

//请求产品信息,包括前5个问题和10个评论,按其提交时间排序。let request = BVProductDisplayPageRequest(productId: "test1") .include(。审查,限制:10).include(。问题s, limit: 5) .sort(by: .reviewSubmissionTime, monotonicSortOrderValue: .descending)
//请求产品信息,包括评论和问题/答案的统计数据。BVProductDisplayPageRequest* request1 = [[BVProductDisplayPageRequest alloc] initWithProductId:@"test1"];[request includeProductIncludeTypeValue:BVProductIncludeTypeValueReviews limit:10];[request includeproductincludetypevaluevalue:BVProductIncludeTypeValueQuestions limit:5];[request sortByReviewsSortOptionValue:(BVReviewsSortOptionValueReviewSubmissionTime)单调sortordervalue:(bv单调sortordervaluedescent);

让我们加载这个请求!

要做到这一点,只需调用负载函数,并适当地使用成功和失败块。

//加载数据请求。负载({ (response: BVProductsResponse) in if let product = response.result { product.reviewStatistics?.averageOverallRating // number of stars: 4.1 product.reviewStatistics?.totalReviewCount // number of reviews: 8 product.qaStatistics?.totalQuestionCount // number of questions: 2 product.qaStatistics?.totalAnswerCount // number of answers: 4 } }) { (errors:[Error]) in // handle failure appropriately }
//加载数据[request load:^(BVProductsRes必威手机版本ponse * _Nonnull response) {BVProduct* product = response.result;if (product) {product. reviewstatistics . averageoverallrating;product.reviewStatistics.totalReviewCount;//星星数量:4.1 product.qaStatistics.totalQuestionCount;//问题数量:2 product.qaStatistics.totalAnswerCount;//回答的数量:4}}failure:^(NSArray * _Nonnull errors){//适当处理失败}];
显示产品显示页面

使用一个BVProductDisplayPageViewControllerBVProductDisplayPageTableViewController,或BVProductDisplayPageCollectionViewController显示此内容。

  • 创建一个新的Cocoa Touch类ProductDisplayViewController让它成为子类BVProductDisplayPageViewController

    和导入BVSDKProductDisplayViewController

  • 现在,修改viewDidLoad加载ProductDisplayPageRequest并设置self.product当加载:

    import BVSDK类ProductPageViewController: BVProductDisplayPageViewController {override func viewDidLoad() {super.viewDidLoad() //为产品"test1"加载产品显示信息let request = BVProductDisplayPageRequest(productId: "test1")请求。load({(response: BVP必威手机版本roductsResponse) in //告诉'BVProductDisplayPageViewController'在这个视图控制器self中显示哪个产品。Product = response。结果}){(错误:[错误])在//处理错误适当}}}
    @ import BVSDK;@interface productdisplaypageviewcontroller: BVProductDisplayPageViewController @end @implementation ProductPageViewController - (void)viewDidLoad {[super viewDidLoad];//装载产品"test1"的产品显示信息BVProductDisplayPageRequest* request = [[BVProductDisplayPageRequest alloc] initWithProductId:@"test1"];[request load:^(BV必威手机版本ProductsResponse * _Nonnull response){//告诉'BVProductDisplayPageViewController'在这个视图控制器self中显示哪个产品。Product = response.result;} failure:^(NSArray * _Nonnull errors){//适当处理错误}];} @end

显示产品显示页面时,使用BVProductQuery获取有用的数据reviewStatistics或者包括前10个BVReview审查,下面讨论。

首先,让我们看一个简单的BVProductQuery

让productQuery = BVProductQuery(productId: "test1") .include(.reviews) .include(.questions)

在上面的代码中,aProductQuery为productIdtest1.我们还包括评论和问题/答案的统计数据。您可能希望在其中包含一些实际内容,如下所示。我们还根据他们的提交时间对所包含的评论进行排序。

让productQuery = BVProductQuery(productId: "test1") .include(。审查,限制:10).include(。问题s, limit: 5) .sort(.reviews(.submissionTime), order: .descending)

让我们加载这个请求!

方法上的async方法,添加一个处理程序并使用成功和失败的案例productQuery对象。

productQuery。handler {(response: BVConversationsQueryResponse < BVProduct >) in if case .failure(let error) = response{//处理失败适当返回}保护case let. bb0。Success (_,必威手机版本 products) = response else {return} if let product = products。first {product.reviewStatistics?averageOverallRating //星级数:4.1 product.reviewStatistics?totalReviewCount //评论的数量:8 product.qaStatistics?来talQuestionCount // number of questions: 2 product.qaStatistics?.totalAnswerCount // number of answers: 4 } } .configure(config) productQuery.async()

产品搜索查询

让pro必威手机版本ductSearchQuery = BVProductSearchQuery(searchQuery: "Large dryer") productSearchQuery.configure(config) .handler {(response: BVConversationsQueryResponse) in if case .failure(let error) = response{//处理失败适当返回}保护case let .success(_, products) = response else {return} //success} productSearchQuery.async()

结果返回的产品在外部ID、产品名称、产必威手机版本品品牌、产品描述、类别名称或类别层次结构名称中同时具有大的和干燥的。

加载更多评论

如前所述,您应该使用ProductDisplayPageRequest加载你的用户将看到的CGC的第一页(多达20个评论)。加载评论时,您应该请求并显示评论BVReviewsCollectionViewBVReviewsTableView容器。评论还可以包括产品和评论。必威手机版本

//添加一个BVReviewsTableView到你的UIViewController并连接outlet。@IBOutlet弱var reviewsTableView: BVReviewsTableView!var review: [BVReview] =[]…//现在从BVReviewsTableView加载评论。//请求10个评论,从索引20开始let reviewsRequest = BVReviewsRequest(productId: "test1", limit: 10, offset: 20) //在reviewsRequest对象reviewsTableView上添加其他选项,用于包含,过滤和排序。load(reviewsRequest, success: {(response) in self。评论=回应。results self.reviewsTableView.reloadData()}){(错误)in print(错误)}
//添加一个BVReviewsTableView到你的UIViewController并连接outlet。@property(弱,非原子)IBOutlet BVReviewsTableView;@property NSArray *审查;...//现在从BVReviewsTableView加载评论。BVReviewsRequest* request = [[BVReviewsRequest alloc] initWithProductId:@"test1" limit:10 offset:20];//在reviewsRequest对象[self.]上添加包含、过滤和排序的其他选项。reviewsTableView load:request success:^(BVReviewsResponse * _Nonnull response) {self. reviewsTableView load:请求成功评论= response.results;(自我。审查sTableView reloadData]; } failure:^(NSArray * _Nonnull errors) { NSLog(@"Error loading reviews"); }];

一个BVReviewsRequest需要三个参数:

  • productId-您想要评论的productId
  • 限制-可获取的最大评论数量(最多20条)
  • 抵消-开始的索引

应该使用限制和偏移量的组合来根据用户的请求加载更多的评论页面。

你可以为请求添加过滤器和排序,如下所示:

//请求10个有照片的评论,从索引0开始,按整体评分排序。let request = BVReviewsRequest(productId: "test1", limit: 10, offset: 0) .filter(on: .hasPhotos, relationalFilterOperatorValue: .equalTo, value: "true") .sort(by: .reviewRating,单调sortordervalue: .ascending)
//请求10个有照片的评论,从索引0开始,按整体评分排序。BVReviewsRequest* request = [[BVReviewsRequest alloc] initWithProductId:@"test1" limit:10 offset:20];[request filterOnReviewFilterValue:BVReviewFilterValueHasPhotos relationalFilterOperatorValue:BVRelationalFilterOperatorValueEqualTo value:@"true"];[request sortByReviewsSortOptionValue:BVReviewsSortOptionValueReviewSubmissionTime monoticsortordervalue: bvmonoticsortordervaluedescent];

类似于ProductDisplayPageRequest,加载评论只需调用load ()方法。BVReviewsCollectionViewBVReviewsTableView如上所示的容器。

显示评论

多个检查应该显示在以下容器视图之一中:

  • BVReviewView
  • BVReviewsTableView
  • BVReviewsCollectionView

每个评审应该使用以下视图之一来显示:

  • BVReviewView
  • BVReviewTableViewCell
  • BVReviewCollectionViewCell

让我们创建一个UIViewController它拥有BVReviewsTableView并在其中显示10个评论使用BVReviewTableViewCell

  • 创建一个新的Cocoa Touch类DemoReviewViewController让它成为子类ui

  • 进口BVSDKDemoReviewViewController的实例BVReviewsTableView

    import UIKit import BVSDK类DemoReviewsViewController: UIViewController {@IBOutlet weak var tableView: BVReviewsTableView!override func viewDidLoad() {super.viewDidLoad()}}
    @ import BVSDK;UIViewController @property (nonatomic, weak) IBOutlet BVReviewsTableView *tableView;@end //…@implementation DemoReviewsViewController - (void)viewDidLoad {[super viewDidLoad];} @end
  • DemoReviewViewController.xib,添加UITableView并添加适当的约束。将其类更改为BVReviewsTableView,并将其连接到您的IBOutlet

  • 的子类UITableViewCell命名DemoReviewTableViewCell

  • 更改类型DemoReviewTableViewCellBVReviewTableViewCell并添加适当的UI元素。在下面的代码中,您可以重写审查属性来更新UI元素:

    import UIKit import BVSDK类DemoReviewTableViewCell: BVReviewTableViewCell {@IBOutlet weak var reviewTitle: UILabel!@IBOutlet弱var reviewText: UILabel!override var review: BVReview!{didSet {reviewTitle。文本=回顾。标题reviewText。文本=回顾。reviewText} } }
    @ import BVSDK;BVReviewTableViewCell @property (nonatomic, weak) IBOutlet UILabel *reviewTitle;@property (nonatomic, weak) IBOutlet UILabel *reviewText;@end //…@实现DemoReviewTableViewCell -(void)setReview:(BVReview *)审查{[超级setReview:审查];self.reviewTitle.text = review.title;self.reviewText.text = review.reviewText;} @end
  • 添加你reviewText而且reviewTitleUILabel年代DemoReviewTableViewCell.xib,并连接插座:

  • 最后,在DemoReviewViewController,使用BVReviewsRequest对象加载10个评论。使用的实例DemoReviewTableViewCell显示:

    import UIKit import BVSDK类DemoReviewsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {@IBOutlet weak var tableView: BVReviewsTableView!var reviews: [BVReview] = [] override func viewDidLoad() {super.viewDidLoad() self. tableview .delegate = self self. tableview . datasource = self self. tableview . datource = self。register(UINib(nibName: "DemoReviewTableViewCell", bundle: nil), forCellReuseIdentifier: "DemoReviewTableViewCell") let request = BVReviewsRequest(productId: "test1", limit: 10,偏移量:20)self.tableView。load(request, success: {(response: BVReviewsResponse) in self。评论=回应。results self.tableView.reloadData()}) {(errors: [Error]) in //处理失败适当}}func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{返回self. views.count} func tableView(_ tableView: UITableView, cellForRowAt indexPath: indexPath) -> UITableViewCell {let cell = tableView. dequeuereusablecell (withIdentifier: "DemoReviewTableViewCell") as!DemoReviewTableViewCell细胞。审查= self.reviews[indexPath.row] return cell } }
    @ import BVSDK;UIViewController @property (nonatomic, weak) IBOutlet BVReviewsTableView *tableView;@property (nonatomic, strong) NSArray*审查;@end //…@implementation DemoReviewsViewController -(void)viewDidLoad {[super viewDidLoad];self. tableview .delegate = self;self. tableview . datasource = self;(自我。tableView registerNib:[UINib nibWithNibName:@"DemoReviewTableViewCell" bundle:nil] forCellReuseIdentifier:@"DemoReviewTableViewCell"];BVReviewsRequest* request = [[BVReviewsRequest alloc] initWithProductId:@"test1" limit:10 offset:20]; [self.tableView load:^(BVReviewsResponse * _Nonnull response) { self.reviews = response.results; [self.tableView reloadData]; } failure:^(NSArray * _Nonnull errors) { // handle failure appropriately }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.reviews count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { DemoReviewTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"DemoReviewTableViewCell"]; cell.review = [self.reviews objectAtIndex:indexPath.row]; return cell; } @end
let reviewQuery = BVReviewQuery(productId: "test1", limit: 10, offset: 0) .configure(config) .handler {(response: BVConversationsQueryResponse < BVReview >) in if case .failure(let error) = response {// error return}保护case let。success(_, reviews) = response else {return} // success} reviewQuery.async()

过滤审查

let reviewQuery = BVReviewQuery(productId: "test1", limit: 10, offset: 4) .filter((.hasPhotos(true), .equalTo)) .filter((.hasComments(false), .equalTo)) .configure(config) .handler {}

您还可以在构造时使用详尽的筛选选项集BVReviewQuery上提到的这个链接

这种评论

let reviewQuery = BVReviewQuery(productId: "test1", limit: 10, offset: 4) .sort(。等级,顺序:.升序).configure(config) .handler {}

您还可以在构造时使用穷尽排序选项集BVReviewQuery上提到的这个链接

加载问题和答案

与回顾类似,您应该使用ProductDisplayPageRequest加载第一页的问题/答案(上20个问题)。加载问题时,应在BVQuestionsCollectionViewBVQuestionsTableView容器::

//添加一个BVQuestionsTableView到你的UIViewController并连接outlet。@IBOutlet弱var questionsTableView: BVQuestionsTableViewvar问题:[BVQuestion] =[]…//现在从BVQuestionsTableView加载问题。//请求10个问题,从索引20开始let questionsRequest = BVQuestionsAndAnswersRequest(productId: "test1", limit: 10, offset: 20)load(questionsRequest, success: {(response) in self。提问=回应。results self.questionsTableView.reloadData()}){(错误)in print(错误)}
//添加一个BVQuestionsTableView到你的UIViewController并连接outlet。IBOutlet BVQuestionsTableView *questionsTableView;@property NSArray *问题;//现在从BVQuestionsTableView加载问题。BVQuestionsAndAnswersRequest* request = [[BVQuestionsAndAnswersRequest alloc] initWithProductId:@"test1" limit:10 offset:20];(自我。questionsTableView load:request success:^(BVQuestionsAndAnswersResponse * _Nonnull response) {self. view load:请求成功问题= response.results;(自我。questionsTableView reloadData];}失败:^ (NSArray
                       * _Nonnull错误){NSLog(@"错误加载问题");});

一个QuestionsAndAnswersRequest需要三个参数:

  • productId-你想问的productId
  • 限制-获取的最大问题数(最多20个)
  • 抵消-开始的索引

应该结合使用limit和offset来根据用户的请求加载更多页的问题。

你可以为请求添加过滤器和排序,如下所示:

//请求10个有答案的问题,从索引0开始,按每个问题的答案数量排序。let request = BVQuestionsAndAnswersRequest(productId: "test1", limit: 10, offset: 20) .filter(on: .questionHasAnswers, relationalFilterOperatorValue: .equalTo, value: "true") .sort(by: .questionSubmissionTime,单调sortordervalue: .ascending)
//请求10个有答案的问题,从索引0开始,按每个问题的答案数量排序。bvquestionsandanswerrequest * request = [[bvquestionsandanswerrequest alloc] initWithProductId:@"test1" limit:10 offset:0];[request filterOnQuestionFilterValue:BVQuestionFilterValueQuestionHasAnswers relationalFilterOperatorValue:BVRelationalFilterOperatorValueEqualTo value:@"true"];[request sortByQuestionsSortOptionValue:BVQuestionsSortOptionValueQuestionLastModeratedTime monoicsortordervalue: bvmonoicsortordervaluedescent];

显示问题和答案

问题和答案应该显示在以下容器视图之一:

  • BVQuestionsView
  • BVQuestionsTableView
  • BVQuestionsCollectionView
  • BVAnswersView
  • BVAnswersTableView
  • BVAnswersCollectionView

每个问题/答案应该使用以下视图之一显示:

  • BVQuestionView
  • BVQuestionTableViewCell
  • BVQuestionCollectionViewCell
  • BVAnswerView
  • BVAnswerTableViewCell
  • BVAnswerCollectionViewCell

让我们创建一个UIViewController它拥有BVQuestionTableView并在其中显示10个问题BVQuestionTableViewCell年代。

  • 创建一个新的Cocoa Touch类DemoQuestionViewController让它成为子类ui

  • 进口BVSDKDemoQuestionViewController的实例BVQuestionsTableView

    导入UIKit导入BVSDK类DemoQuestionViewController: UIViewController {@IBOutlet弱var questionsTableView: BVQuestionsTableView!override func viewDidLoad() {super.viewDidLoad()}}
    @ import BVSDK;@interface DemoQuestionsViewController: UIViewController @property (nonatomic, weak)@end //…@implementation DemoQuestionsViewController - (void)viewDidLoad {[super viewDidLoad];} @end
  • DemoQuestionViewController.xib,添加UITableView并添加适当的约束。将其类更改为BVQuestionsTableView,并将其连接到您的IBOutlet

  • 的子类UITableViewCell命名DemoQuestionTableViewCell

  • 更改类型DemoQuestionTableViewCellBVQuestionTableViewCell并添加适当的UI元素。在下面的代码中,您可以重写问题属性来更新UI元素:

    导入UIKit导入BVSDK类DemoQuestionTableViewCell: BVQuestionTableViewCell {@IBOutlet弱var questionSummary: UILabel!@IBOutlet弱变量问题:UILabel!override var question: BVQuestion!{didSet {questionSummary。文本=问题。questionSummaryquestionDetails.文本=问题。questionDetails} } }
    @ import BVSDK;@interface DemoQuestionTableViewCell: BVQuestionTableViewCell @property (nonatomic, weak)@property(非原子的,弱的)IBOutlet UILabel *问题细节;@end //…@实现DemoQuestionTableViewCell -(void)setQuestion:(BVQuestion *)问题{[super setQuestion:问题];self.questionSummary.text = question.questionSummary;self.questionDetails.text = question.questionDetails;} @end
  • 添加你questionSummary而且questionDetailsUILabel年代DemoQuestionTableViewCell.xib,并连接插座:

  • 最后,在DemoQuestionViewController,使用BVQuestionsAndAnswersRequest对象加载10个问题及其相关答案。使用的实例DemoQuestionTableViewCell显示:

    答案不会在本教程中显示,但应该与问题一起显示。
    import UIKit import BVSDK类DemoQuestionViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {@IBOutlet weak var tableView: BVQuestionsTableView!var questions: [BVQuestion] = [] override func viewDidLoad() {super.viewDidLoad() self. tableview .delegate = self self. tableview . datasource = self self. tableview。register(UINib(nibName: "DemoQuestionTableViewCell", bundle: nil), forCellReuseIdentifier: "DemoQuestionTableViewCell") let request = BVQuestionsAndAnswersRequest(productId: "test1", limit: 10,偏移量:20)self.tableView。load(request, success: {(response: BVQuestionsAndAnswersResponse) in self。提问=回应。results self.tableView.reloadData()}) {(errors: [Error]) in //处理失败适当}}func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{返回self. problems .count} func tableView(_ tableView: UITableView, cellForRowAt indexPath: indexPath) -> UITableViewCell {let cell = tableView. dequeuereusablecell (withIdentifier: "DemoQuestionTableViewCell") as!DemoQuestionTableViewCell细胞。问题= self.questions[indexPath.row] return cell } }
    @ import BVSDK;@interface DemoQuestionsViewController: UIViewController @property (nonatomic, weak) IBOutlet BVQuestionsTableView *tableView;@property (nonatomic, strong) NSArray* questions;@end //…@implementation DemoQuestionsViewController -(void)viewDidLoad {[super viewDidLoad];self. tableview .delegate = self;self. tableview . datasource = self;(自我。tableView registerNib:[UINib nibWithNibName:@"DemoQuestionTableViewCell" bundle:nil] forCellReuseIdentifier:@"DemoQuestionTableViewCell"];bvquestionsandanswerrequest * request = [[bvquestionsandanswerrequest alloc] initWithProductId:@"test1" limit:10 offset:20]; [self.tableView load:request success:^(BVQuestionsAndAnswersResponse * _Nonnull response) { self.questions = response.results; [self.tableView reloadData]; } failure:^(NSArray * _Nonnull errors) { // handle failure appropriately }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.questions count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { DemoQuestionTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"DemoQuestionTableViewCell"]; cell.question = [self.questions objectAtIndex:indexPath.row]; return cell; } @end
let questionQuery = BVQuestionQuery(productId: "test1", limit: 10, offset: 0) .configure(config) .handler {(response: BVConversationsQueryResponse < BVQuestion >) in if case .failure(let error) = response {// error return}保护case let. config (config) .handler {(response: BVConversationsQueryResponse < BVQuestion >) in if case .failure(let error) = response {// error return}success(_, questions) = response else {return} // success} questionQuery.async()

过滤问题并包含答案

let questionQuery = BVQuestionQuery(productId: "test1", limit: 10,offset: 0) .include(.answers) .filter((.hasAnswers(true), .equalTo)) .configure(config) .handler {}

您还可以在构造时使用详尽的筛选选项集BVQuestionQuery上提到的这个链接

排序的问题

let questionQuery = BVQuestionQuery(productId: "test1", limit: 10, offset: 0) .sort(。totalAnswerCount, order: . descent) .configure(config) .handler {}

您还可以在构造时使用穷尽排序选项集BVQuestionQuery上提到的这个链接

加载评审意见

注释可以通过单个注释ID加载,也可以通过带有limit和offset参数的评审ID加载注释。简单地构造一个BVCommentsRequest对象,并选择提供的默认初始化式之一。下面提供的示例演示了如何从给定的评论ID获取评论列表。

//可选地,注释可以有包含,过滤,排序添加到请求中。request.addInclude request.addFilter((.)。contentLocale, filterOperator: . equalto,值:"en_US") request. addcommentsort (. commentslastmoderatedtime, order: . descent)请求。在self.comments中加载({(response) = response。results // BVComment对象数组//在你的UI中显示注释}){(错误)in print("错误获取注释:\(error.first!.localizedDescription)")}
BVCommentsRequest *request = [[BVCommentsRequest alloc] initWithProductId:@"myProductId" andReviewId:@"myReviewId" limit:99 offset:0];//可选的,注释可以包含,过滤和排序添加到请求中。(请求includeCommentIncludeTypeValue: BVCommentIncludeTypeValueCommentReviews);[request sortByCommentsSortOptionValue:BVCommentsSortOptionValueCommentLastModeratedTime monoicsortordervalue: bvmonoicsortordervaluedecline];[request filterOnCommentFilterValue:BVCommentFilterValueCommentContentLocale relationalFilterOperatorValue:BVRelationalFilterOperatorValueEqualTo value:@"en_US"];[request load:^(BVCommentsResponse * _Nonnull response) {// success self.comments = response.results;// BVComment对象数组//在UI中显示注释}失败:^(NSArray * _Nonnull errors) {// error NSLog(@" error Loading comments: %@", errors. firstobject . localizeddescription);});

注释可以通过单个注释ID加载,也可以通过带有limit和offset参数的评审ID加载注释。简单地构造一个BVCommentsQuery对象,并选择提供的默认初始化式之一。下面提供的示例演示了如何从给定的评论ID获取评论列表。

让commentQuery = BVCommentsQuery(productId: "productId", reviewId: "reviewId",limit: 10) commentQuery .configure(config) .handler {(response: BVConversationsQueryResponse < BVComment >) in if case .failure(let error) = response {// error return}保护情况让。success(_, comments) = response else {return} // success} commentQuery.async()

过滤器评审意见

让commentQuery = BVCommentsQuery(productId: "productId", reviewId: "reviewId",limit: 10) commentQuery .filter((。contentLocale(Locale(标识符:"en_US")), .equalTo)) .configure(config) .handler {}

您还可以在构造时使用详尽的筛选选项集BVCommentsQuery上提到的这个链接

排序评审意见

让commentQuery = BVCommentsQuery(productId: "productId", reviewId: "reviewId",limit: 10)submissionTime, order: . descent) .configure(config) .handler {}

您还可以在构造时使用穷尽排序选项集BVCommentsQuery上提到的这个链接

显示批量评级

若要在类别页面上显示产品评级统计信息,请使用BVBulkRatingsRequest.例如,在这样一个分类页面上:

获得每个产品的评级统计数据可以通过以下单个请求完成:

//四个产品的负载统计信息。必威手机版本每个请求最多可以加载50个。let productIds = ["test1", "test2", "test3", "test4"] let request = BVBulkRatingsRequest(productIds: productIds, statistics: .bulkRatingAll)
//四个产品的负载统计信息。必威手机版本每个请求最多可以加载50个。NSArray * productIds = @[@“test1”@“test2”@“test3”@“test4”);BVBulkRatingsRequest* request = [[BVBulkRatingsRequest alloc] initWithProductIds:productIds statistics: BVBulkRatingIncludeTypeValueBulkRatingReviews];

可以加载:

请求。负载({ (response: BVBulkRatingsResponse) in let ratings = response.results for rating in ratings { let productId = rating.productId let averageOverallRating = rating.reviewStatistics?.averageOverallRating let totalReviewCount = rating.reviewStatistics?.totalReviewCount } }) { (errors: [Error]) in // handle failure appropriately }
[请求加载:^(BVBulkRatingsResponse * _Nonnull response) {NSArray* ratings = response.results;for (BV必威手机版本ProductStatistics* rating in ratings) {NSString* productId = rating.productId;NSNumber* averageOverallRating = rating.reviewStatistics.averageOverallRating;NSNumber* totalReviewCount = rating.reviewStatistics.totalReviewCount;}} failure:^(NSArray * _Nonnull errors){//适当处理失败}];

若要在类别页面上显示产品评级统计信息,请使用BV必威手机版本ProductStatisticsQuery.例如,在这样一个分类页面上:

获得每个产品的评级统计数据可以通过以下单个请求完成:

let productIds = ["test1", "test2", "test3", "test4"] let usLocale: Locale = Locale(标识符:"en_US") guard let productS必威手机版本tatisticsQuery = BVProductStatisticsQuery(productIds: productIds) else {return} productStatisticsQuery .stats(.nativeReviews) .stats(.reviews) .filter((.contentLocale(usLocale), .equalTo) .configure(config) .handler {(response:BVConversationsQueryResponse) in if case .failure(let error) = response {print(error) return} guard case let .success(_, productStatistics) = response else {return} guard let firstproductstatistics: BVProductStatistics = productStatistics。首先,让reviewStatistics = firstProduct必威手机版本Statistic。reviewStatistics,let nativeReviewStatistics = firstProductStatistic.nativeReviewStatistics else { return } print(reviewStatistics) } productStatisticsQuery.async()

您还可以在构造时使用详尽的筛选选项集BV必威手机版本ProductStatisticsQuery上提到的这个链接

正在加载作者的简介

“对话”的作者简介以BVAuthorRequest对象。此请求对象是创建参数和获取作者概要所需要的全部内容。作者的响应在响应对象中找到BVAuthorResponse.作者简介的回复可以包括由作者撰写并批准出版的评论、问题和答案。

徽章显示

请注意,对话API不会返回图像链接。Conversation API客户端的显示取决于客户端的创造性解释。有关更多信息,请参阅对话开发人员徽章文件

let request = BVAuthorRequest(authorId: "theAuthorsId") // stats includes(可选). includestatistics (. authoranswers) . includestatistics (. authorquestions) . includestatistics (. authorreviews) //其他includes(可选).include(. authorsid)。authorReviews, limit: 10) .include(。authorQuestions,限制:10).include(。authorAnswers,限制:10).include(。authorReviewComments, limit: 10) //排序,可选。sort(by: . answersubmissiontime,单调sortordervalue: . descent) .sort(by: . reviewsubmissiontime,单调sortordervalue: . descent) .sort(by: . questionsubmissiontime,单调sortordervalue: . descent)请求。load({(response) in // success——将数据加载到你的UI print(response)}) {(error) in // error -处理错误print(error)}
BVAuthorRequest *request = [[BVAuthorRequest alloc] initWithAuthorId: @"authorId"];(请求includeStatistics: BVAuthorIncludeTypeValueAuthorReviewComments);(请求includeStatistics: BVAuthorIncludeTypeValueAuthorQuestions);(请求includeStatistics: BVAuthorIncludeTypeValueAuthorAnswers);[request includeAuthorIncludeTypeValue:BVAuthorIncludeTypeValueAuthorAnswers limit:5];[request includeauthorincludetypevalueauthorquestions limit:5];[request includeAuthorIncludeTypeValue:BVAuthorIncludeTypeValueAuthorReviewComments limit:5];[request includetypevalue:BVAuthorIncludeTypeValueAuthorReviews limit:5];[request load:^(BVAuthorResponse * _Nonnull response) {// Success!]NSLog(@"成功加载的配置文件:%@",响应); } failure:^(NSArray * _Nonnull errors) { // Error : ( NSLog(@"ERROR loading author: %@", errors.description); }];

“对话”的作者简介以BVAuthorQuery对象。此请求对象是创建参数和获取作者概要所需要的全部内容。作者的响应在响应对象中找到BVConversationsQueryResponse < BVAuthor >.作者简介的回复可以包括由作者撰写并批准出版的评论、问题和答案。

徽章显示

请注意,对话API不会返回图像链接。Conversation API客户端的显示取决于客户端的创造性解释。有关更多信息,请参阅对话开发人员徽章文件

let authorQuery = BVAuthorQuery(authorId: " authorId ") // stats包括.stats(.answers) .stats(.questions) .stats(.reviews) //其他包括.include(. reviews)。审查,限制:10).include(。问题s, limit: 10) .include(.answers, limit: 10) .include(.comments, limit: 10) // sorts .sort(.answers(.submissionTime), order: .descending) .sort(.reviews(.submissionTime), order: .descending) .sort(.questions(.submissionTime), order: .descending) .configure(config) .handler { (response: BVConversationsQueryResponse) in // success if case .failure(let error) = response { print(error) return } guard case let .success(_, authors) = response else { return } guard let author: BVAuthor = authors.first, let qaStatistics: BVQAStatistics = author.qaStatistics, let reviewStatistics: BVReviewStatistics = author.reviewStatistics, let ratingDistribution: BVRatingDistribution = reviewStatistics.ratingDistribution, let averageOverallRating: Double = reviewStatistics.averageOverallRating, let reviews: [BVReview] = author.reviews, let questions: [BVQuestion] = author.questions, let answers: [BVAnswer] = author.answers, let comments: [BVComment] = author.comments else { return } } authorQuery.async()

您还可以在构造时使用详尽的筛选选项集BVAuthorQuery上提到的这个链接

您还可以在构造时使用穷尽排序选项集BVAuthorQuery上提到的这个链接

若要在类别页面上显示产品评级统计信息,请使用BVBulkRatingsRequest.例如,在这样一个分类页面上:

获得每个产品的评级统计数据可以通过以下单个请求完成:

//四个产品的负载统计信息。必威手机版本每个请求最多可以加载50个。let productIds = ["test1", "test2", "test3", "test4"] let request = BVBulkRatingsRequest(productIds: productIds, statistics: .All)
//四个产品的负载统计信息。必威手机版本每个请求最多可以加载50个。NSArray * productIds = @[@“test1”@“test2”@“test3”@“test4”);BVBulkRatingsRequest* request = [[BVBulkRatingsRequest alloc] initWithProductIds:productIds statistics:BulkRatingsStatsTypeReviews];

可以加载:

请求。负载({ (response: BVBulkRatingsResponse) in let ratings = response.results for rating in ratings { let productId = rating.productId let averageOverallRating = rating.reviewStatistics?.averageOverallRating let totalReviewCount = rating.reviewStatistics?.totalReviewCount } }) { (errors: [NSError]) in // handle failure appropriately }
[请求加载:^(BVBulkRatingsResponse * _Nonnull response) {NSArray* ratings = response.results;for (BV必威手机版本ProductStatistics* rating in ratings) {NSString* productId = rating.productId;NSNumber* averageOverallRating = rating.reviewStatistics.averageOverallRating;NSNumber* totalReviewCount = rating.reviewStatistics.totalReviewCount;}} failure:^(NSArray * _Nonnull errors){//适当处理失败}];

若要在类别页面上显示产品评级统计信息,请使用BV必威手机版本ProductStatisticsQuery.例如,在这样一个分类页面上:

获得每个产品的评级统计数据可以通过以下单个请求完成:

let productIds = ["test1", "test2", "test3", "test4"] let 必威手机版本productStatisticsQuery = BVProductStatisticsQuery(productIds: productIds) .handler {(response: BVConversationsQueryResponse < BVProductStatistics >) in if case .failure(let error) = response{//处理失败适当返回}保护case let. BVProductStatistics。success(_, 必威手机版本productStatistics) = response else {return} let ratings = productStatistics for ratings中的评级{let productId = rating。productId let averageOverallRating =评分。reviewStatistics吗?. averageoverallrating let totalReviewCount =评分。reviewStatistics吗?.totalReviewCount}} pr必威手机版本oductstatisticsury .async(

加载回顾要点

通过指定产品ID和客户端ID加载审查重点(优点和缺点)。

  1. 构造一个BVReviewHighlightsRequest对象,并传递产品ID。下面提供的示例演示了如何获取给定产品ID的Review Highlights。
    let request = BVReviewHighlightsRequest(productId: "productId")请求。负载({ (response) in if let positives = response.reviewHighlights.positives { // Array of BVReviewHighlight objects // display positives in your UI for positive in positives { let title = positive.title // PRO title } } if let negatives = response.reviewHighlights.negatives { // Array of BVReviewHighlight objects // display negatives in your UI for negative in negatives { let title = negative.title // CON title } } }) { (error) in // handle failure appropriately }
    BVReviewHighlightsRequest *reviewHighlightsRequest = [[BVReviewHighlightsRequest alloc] initWithProductId:@"productId"];[reviewHighlightsRequest load:^(BVReviewHighlightsResponse * _Nonnull response) {NSArray *positives = response. reviewhights .positives;for (BVReviewHighlight *positive in positive) {NSString *title = positive.title;// PRO title} NSArray< bvreviewhightlight *> *negatives = response. reviewhightlights .negatives;for (BVReviewHighlight *negative in negatives) {NSString *title = negative.title;// CON title}} failure:^(NSArray * _Nonnull errors) {// error NSLog(@" error Loading Review Highlights: %@", errors. firstobject . localizeddescription);});
  2. 在创建获取Review Highlights的请求之前,将客户端ID传递给配置,如下面的代码块所示:
    let configDict = ["clientId": "YOUR_CLIENT_ID", "apiKeyConversations": "YOUR_API_KEY"];BVSDKManager。配置(withConfiguration: configDict, configType: .staging)
    NSDictionary *configDict = @{@" client_id ":@" YOUR_CLIENT_ID", @"apiKeyConversations":@"YOUR_API_KEY"};[BVSDKManager configureWithConfiguration:configDict configType:BVConfigurationTypeStaging];

通过传递客户端ID和产品ID加载审查重点(优点和缺点)。简单地构造一个BVProductReviewHighlightsQuery对象,并传递客户端ID和产品ID。下面提供的示例演示了如何获取给定客户端ID和产品ID的Review Highlights。

var config: BVReviewHighlightsConfiguration = {() -> BVReviewHighlightsConfiguration in let analyticsConfig: BVAnalyticsConfiguration = .configuration(locale: locale(标识符:"en_US"), configType: .staging(clientId: "clientId"))返回BVReviewHighlightsConfiguration。display(configType: .staging(clientId: "clientId"), analyticsConfig: analyticsConfig)}() let reviewHighlightsQuery = BVProductReviewHighlightsQuery(clientId: "clientId", productId: " testproductId") .configure(config) .handler {(response: BVReviewHighlightsQueryResponse) in if case .failure(let error) = response {print(error) return} guard case let .success(reviewHighlights) = response else {return} if let negatives = reviewHighlights。如果let positive = reviewHighlights,则返回negative{为negative中的negative {print(negative.title)}}。positive{对于positive中的positive {print(positive. bestexamples ?.first?.reviewTitle)}}} reviewHighlightsQuery.async()