0

我创建了一个后端 API 项目,并且在没有传递任何参数时成功调用了我的应用程序中的端点公开的 API。

GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];

此方法设计有一个可选参数。如生成 Google API 发现服务所示:

// Method: newerAPI.mymodel.list
//  Optional:
//   pupil: NSString
//  Authorization scope(s):
//   kGTLAuthScopeNewerAPIUserinfoEmail
// Fetches a GTLNewerAPIMyModelCollection.
+ (instancetype)queryForMymodelList;

我想在调用 API 时传递一个瞳孔参数,但这样做有困难。

NSString *pupil = @"Test Name";
GTLServiceNewerAPI *service = [self helloworldService];
GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList:(NSString*)pupil];

选择器“queryForMymodelList:”没有已知的类方法

4

1 回答 1

0

因为pupil是一个可选参数,所以它不会为它生成构造函数——将它放在构造函数中会使创建GTLQueryNewerAPI.

您所要做的就是:

NSString *pupil = @"Test Name";
GTLServiceNewerAPI *service = [self helloworldService];
GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];
query.pupil = pupil;

您应该看到pupil在头文件中声明的属性GTLQueryNewerAPI(通常类似于以下内容:

@interface GTLQueryNewerAPI : GTLQuery
//
// Parameters valid on all methods.
//

// Selector specifying which fields to include in a partial response.
@property (nonatomic, copy) NSString *fields;

//
// Method-specific parameters; see the comments below for more information.
//
@property (nonatomic, copy) NSString *pupil;

...
@end

如果这样声明,该pupil属性将在需要时设置。

于 2016-01-16T21:40:44.350 回答