我已经创建了一个后端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:"没有已知的类方法
由于pupil
是一个可选参数,它不会为其生成构造函数-将其放入构造函数将使其成为创建GTLQueryNewerAPI
实例所必需的参数。
你所要做的就是:
NSString *pupil = @"Test Name";
GTLServiceNewerAPI *service = [self helloworldService];
GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];
query.pupil = pupil;
您应该看到在GTLQueryNewerAPI
的头文件中声明的pupil
属性(通常类似于以下内容:
@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
属性,则该属性将在需要时进行设置。